Hi all,
I'm experimenting with hiding the .php extension for my webpages using the .htaccess file. Seems to work, but I have a few questions...
Let's assume I have a page "www.mysite.com/test.php", and the rewrite changes it to "www.mysite.com/test"
1) I'm assuming my internal links should still reference "test.php"
2) I'm assuming external links should reference "www.mysite.com/test" (without the extension)?
3) What is the impact on SEO?
4) Are there any "cons" to using this technique I should be aware of?
5) Looking at the code below, will this also work for files in deeper subfolders? (i.e. www.mysite.com/folder/page.php)
Any information appreciated! (the code I'm using is below - feel free to offer any suggestions)
Thanks all!
CODE:
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.mysite.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.mysite.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]