Htaccess: add/remove trailing slash from URL

前端 未结 4 1620
时光取名叫无心
时光取名叫无心 2020-11-22 05:36

My website runs a script called -> WSS wallpaper script

My Problem -> I have been trying to force remove or add trailing slash to the end of my URL

4条回答
  •  臣服心动
    2020-11-22 06:08

    This is what I've used for my latest app.

    # redirect the main page to landing
    ##RedirectMatch 302 ^/$ /landing
    
    # remove php ext from url
    # https://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess
    RewriteEngine on 
    
    # File exists but has a trailing slash
    # https://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?(.*)/+$ /$1 [R=302,L,QSA]
    
    # ok. It will still find the file but relative assets won't load
    # e.g. page: /landing/  -> assets/js/main.js/main
    # that's we have the rules above.
    RewriteCond %{REQUEST_FILENAME} !\.php
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule ^/?(.*?)/?$ $1.php
    

提交回复
热议问题