URL Rewriting adding slash at the end breaks my css links

前端 未结 3 1291
一整个雨季
一整个雨季 2021-01-23 03:58

I\'m using Apache mod_rewrite to rewrite my url\'s in a PHP application. I have a login.php in my application root. I wrote the following lines in .htaccess file (I\'m using HTM

3条回答
  •  梦毁少年i
    2021-01-23 04:26

    One way is to have a new redirect rule to remove trailing slash and then your css/js would not be a problem:

    RewriteEngine On
    RewriteBase /apx/
    
    # remove trailing slash from non-directories
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+?)/$ $1 [NE,R=302,L]
    
    RewriteRule ^signin/?$ login.php [L,NC]
    

    However also consider using absolute paths for css/js e.g.

    
    

    Or else you can add this in the section of your page's HTML:

    
    

提交回复
热议问题