在 .htaccess 中使用 Mod 重写来使"prettify" URL 正常工作



我有一个网站,该网站有多个页面,这些页面是通过从数据库中获取数据而生成的,查看这些页面的链接看起来像这样。

www.mywebsite.com/article.php?id=01&title=title

我正在尝试设置一个mod重写以使服务器显示相同的网页,但使用一个看起来更好的URL。

www.mywebsite.com/article/01/title

我在.htaccess文件中使用的代码行是

RewriteRule ^article/([0-9]+)/([A-Za-z0-9-+]+)/?$ /article.php?id=$1&title=$2 [NC,L,QSA]

现在,当我返回网站并输入以下URL时www.mywebsite.com/article/01/title

它显示正确的内容,但页面根本没有附带样式?

我的完整.htaccess如下

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
# Needed before any rewriting
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^/]+/)*(default|index).   (html|php|htm) HTTP/ [NC]
RewriteRule ^(([^/]+/)*)(default|main|index).(html|php|htm)$ http://www.example.com/$1 [R=301]
RewriteRule ^article/([0-9]+)/([A-Za-z0-9-+]+)/?$ /article.php?id=$1&title=$2 [NC,L,QSA]

有人可以告诉我我做错了什么吗?非常感谢

,这意味着您可能已经连接了与"/"开头的相对路径的CSS文件,请更改此

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

我认为您的重写规则没有问题,您的URL中只有虚拟目录。

最新更新