【发布时间】:2017-12-05 10:12:10
【问题描述】:
我有一个网站,其中有几个页面是通过从数据库中提取数据生成的,查看这些页面的链接如下所示。
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]
现在当我返回我的网站并输入以下网址时 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 文件的相对路径吗?
-
在页面 HTML 的
<head>部分下方添加:<base href="/" />
标签: php .htaccess mod-rewrite url-rewriting