Mobile app version of vmapp.org
Login or Join
Jennifer507

: Clean URLs without PHP file extension I want to make my URLs clean, for example: http://sample.com/about-me instead of: http://sample.com/about-me.php This is my code: RewriteEngine On

@Jennifer507

Posted in: #CanonicalUrl #CleanUrls #Htaccess #UrlRewriting

I want to make my URLs clean, for example:
sample.com/about-me instead of: sample.com/about-me.php
This is my code:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php


But I can still access sample.com/about-me.php.
How can I have sample.com/about-me, so sample.com/about-me.php will be permanently redirected to that?

I think this technique is good for SEO because canonicalization needs just one URL. If I use two URLs that both can be accessed, I think that's not good for SEO and can make search engines confused, right?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Jennifer507

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

The reasons for using clean URLs include:


They make it easier for users to identify in search engine results and links on websites as to where they would be sent to if clicked on.
They make links in search engines and websites appear more relevant to the content that they're interested in, versus a filename or query parameters, and thus users will be more inclined to click on them.
They can make it easier for search engines to understand complicated URLs (e.g., if it contains lots of parameters).


It is perfectly OK to have more than one URL point to the same resource, providing that you add a canonical URL to the page to let search engines know the preferred URL to index. Alternatively, you can request that one of the URLs be excluded from indexing in your robots.txt file.

Most users could probably understand a simple URL like the following, and certainly search engines can, so the benefits of converting it into a clean URL are likely not much:
sample.com/about-me.php
However, if you still want to remove the PHP extension in the URL, you can try using this in your .htaccess file:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ .php

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme