Jump to content

ht access force remove extensions


yandoo

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/273146-ht-access-force-remove-extensions/
Share on other sites

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.