: 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
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?
More posts by @Jennifer507
1 Comments
Sorted by latest first Latest Oldest Best
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
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.