在我的网站上,我写博客,填充以下类型的链接
http://example.com/blog.php?article=article-title-goes-here
我使用下面的htaccess代码有漂亮的url与htaccess,但一半的代码不工作
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example'.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule blog/article/(.*)/ blog.php?article=$1
RewriteRule blog/article/(.*) blog.php?article=$1
网站被重定向到www.example.com,但它不影响博客url
编辑:当我输入url
http://asinnetworks.com/blog/article/Hackers-take-over-Israel-army-Twitter-account/原来是
http://asinnetworks.com/blog.php?article=Hackers-take-over-Israel-army-Twitter-account页面加载但不加载CSS和其他东西
在css, js, images文件中使用绝对路径而不是相对路径。这意味着您必须确保这些文件的路径以http://
或斜杠/
开头。
或者
你可以尝试在你的页面的HTML标题中添加:<base href="/" />
或者在www
强制规则下面添加此重写规则
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example'.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^article/(.+?'.(?:jpe?g|gif|bmp|png|tiff|css|js))$ /$1 [L,NC,R=301]
RewriteRule blog/article/([^/]+)/?$ blog.php?article=$1 [L,QSA]