Jase Wolf
New Member
Hi, on my sites, I'm wanting extentions to be removed, and then any extentioned requests get rewritten, also removing the trailing slash.
By doing this, people can land on the page they want whether they put html, php, htm, or shtml (if there's more common extentions for web pages will be good to know) or no extention at all.
Trouble is, folder/file redirects work fine before I place in the htaccess rules I have put together, but after, nothing I do works.
Could anyone work out what is the culprit and what I can do instead to have the same effect but with working redirects?
I asked this on my hosting provider's forums InstaFree.com, and one suggested it could be the ordering is wrong? He suggested to put redirects above these rules. Trouble is though, Cpanel redirect tool places redirect entries on the bottom, so that'd not be a solution.
Here's the code. Thanks, Jase Wolf
By doing this, people can land on the page they want whether they put html, php, htm, or shtml (if there's more common extentions for web pages will be good to know) or no extention at all.
Trouble is, folder/file redirects work fine before I place in the htaccess rules I have put together, but after, nothing I do works.
Could anyone work out what is the culprit and what I can do instead to have the same effect but with working redirects?
I asked this on my hosting provider's forums InstaFree.com, and one suggested it could be the ordering is wrong? He suggested to put redirects above these rules. Trouble is though, Cpanel redirect tool places redirect entries on the bottom, so that'd not be a solution.
Here's the code. Thanks, Jase Wolf
Code:
# Rewrite urls to remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)/$
RewriteRule ^ /%1 [R=301,L]
# Redirect http to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Rewrite files to extensionless urls
RewriteRule ^([^/.]+)$ /$1.php [L]
RewriteRule ^([^/.]+)$ /$1.html [L]
RewriteRule ^([^/.]+)$ /$1.shtml [L]
RewriteRule ^([^/.]+)$ /$1.htm [L]
# Redirect external requests to extensionless urls
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ $1 [R=301,L]
RewriteCond %{THE_REQUEST} ^(.+)\.html([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.html$ $1 [R=301,L]
RewriteCond %{THE_REQUEST} ^(.+)\.htm([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.htm$ $1 [R=301,L]
RewriteCond %{THE_REQUEST} ^(.+)\.shtml([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.shtml$ $1 [R=301,L]