yandoo Posted January 14, 2013 Share Posted January 14, 2013 Hiya ive edited my ht access file on my webserver to enable extensions to be hidden from the url. This works fine removing the extensions but the links on my website still have the .html and .php extensions built into the hyperlinks so that when clicked the extensions still appear in the url. e.g this works fine: www.mywebsite/page1 but when i click the hyperlink within the page the url says: www.mywebsite/page1.html So how can i force it to remove the extension rather than just enable a url to work without an extension? RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html Thank you Quote Link to comment https://forums.phpfreaks.com/topic/273146-ht-access-force-remove-extensions/ Share on other sites More sharing options...
requinix Posted January 14, 2013 Share Posted January 14, 2013 (edited) You should fix the links. The actual links themselves. In fact you must for any forms that have action=post. Otherwise you can look at the REQUEST_URI to determine if the URL they're trying has an extension. # remove .php and .html extensions RewriteCond %{REQUEST_URI} ^([^?]+)\.(php|html)($|\?.*) RewriteRule ^ %1%3 [L] # make extensions optional for any file type recognized by Apache Options +MultiViews # if the Options doesn't work then you're stuck with mod_rewrite #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d #RewriteCond %{REQUEST_FILENAME}.php -f #RewriteRule .* $0.php [L] #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d #RewriteCond %{REQUEST_FILENAME}.html -f #RewriteRule .* $0.html [L] Edited January 14, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/273146-ht-access-force-remove-extensions/#findComment-1405626 Share on other sites More sharing options...
yandoo Posted January 14, 2013 Author Share Posted January 14, 2013 Thank you Just to clarify you mean change the hyperlinks on the website so they dont have the .html or .php anymore? Quote Link to comment https://forums.phpfreaks.com/topic/273146-ht-access-force-remove-extensions/#findComment-1405630 Share on other sites More sharing options...
requinix Posted January 14, 2013 Share Posted January 14, 2013 Yeah, in the actual HTML. Quote Link to comment https://forums.phpfreaks.com/topic/273146-ht-access-force-remove-extensions/#findComment-1405631 Share on other sites More sharing options...
yandoo Posted January 14, 2013 Author Share Posted January 14, 2013 Ill do that then. Thank you very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/273146-ht-access-force-remove-extensions/#findComment-1405654 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.