简体   繁体   English

添加.htaccess后跟斜杠和CSS太糟糕了

[英]add .htaccess a trailing slash and css got awful

I'd like to put a trailing slash to my url with .htaccess 我想用.htaccess在URL后面加上斜杠

My .htaccess is 我的.htaccess

        RewriteEngine On
        RewriteBase /
        RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
        RewriteRule ^ %1 [R=301,L]
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME}.php -f
        RewriteRule ^(.*?)/?$ $1.php [NC,L]

When I try to use www.example.com/about-us it works fine but when the Url is www.example.com/about-us/ my css url won't load the website get horrible. 当我尝试使用www.example.com/about-us它可以正常工作,但当网址为www.example.com/about-us/我的CSS网址无法加载,这会使网站变得非常糟糕。 Sorry for my bad english. 对不起,我的英语不好。

You need to use absolute URL's or use the base tag in the head section of your site after doing those pretty URL rewrites. 进行pretty URL重写后,您需要使用绝对URL或使用网站标题中的base标签。

With CSS use / before the path. 对于CSS,请在路径前使用/

<link rel="stylesheet" type="text/css" href="/path/to/style.css">

Or you can use the base. 或者,您可以使用底座。

<head>
<base href="http://www.example.com/">
</head>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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