简体   繁体   中英

mod rewrite in .htaccess to hide url extensions not working

Just can't get rid of my url extensions.

I'm building a static site so all content is in HTML format and files have .html extensions. I want to hide the .html extensions from users so my url would read websitename.com/about

I have modified the .htaccess file where my site is hosted, it now looks like this

# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName boldfacedesign.co.uk
AuthUserFile /home/boldface/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/boldface/public_html/_vti_pvt/service.grp

RewriteBase /
RewriteEngine on
RewriteCond %{RQUEST_FILENAME} !-d
RewriteCond %{RQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1html [L,QSA]

At present this just isn't working.

As you can see this file is in the public_html folder, is that the correct place for it? Or is there something else I need to do to enable the rewrite rule to take effect? Or do I simply need to be patient and wait a day for the changes to take affect?

I've been googling this for hours now and I'm getting nowhere.

Not sure if these are typos or what, but your rewrite rules should probably look more like:

RewriteBase /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L,QSA]

Or if you have trailing slashes, the last line should be:

RewriteRule ^(.*?)/?$ $1.html [L,QSA]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM