.htaccess Remove URL Extension, Add Trailing Slash

前端 未结 1 803
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 19:03

I have been trying to get this to work on my client\'s server for a website I am developing, but I simply cannot get it to work. Basically I am trying to remove the .html ex

相关标签:
1条回答
  • 2021-01-06 19:13

    Modify the .htaccess file and insert the following

    Explanation: http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/

    Example:

    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]
    

    Update the links on the pages

    Then, all hyperlinks, css links, images, etc, will need to be updated to have either an absolute URL (http://www.site.com/style.css) or relative and begin with ../. Otherwise you will encounter issues such as CSS that doesn't load, links that don't work, etc.

    0 讨论(0)
提交回复
热议问题