Jump to content

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]

Edited by requinix
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.