问题
I am trying to replace everything ending with the extension html (.html
) with a trailing (\
) slash i.e.
http://www.example.com/ibizaparty.html
to http://www.example.com/ibizaparty/
How can this be resolved using .htaccess i.e. redirect/rewrite rules?
Your help is greatly appreciated?
回答1:
I'm giving you the code but for future questions please look around and search the site before you just make a question that has been answered millions of times.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html
# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
来源:https://stackoverflow.com/questions/32166307/htaccess-replace-everything-ending-html-with-a-trailing-slash