我的 htaccess 是
Options -Multiviews
RewriteEngine On
RewriteBase /
# Force search engines to use www.mommy-info.com
RewriteCond %{HTTP_HOST} !^www\.mommy-info\.com$
RewriteRule ^(.*) http://www.mommy-info.com/$1 [R=301,L]
# Specify search friendly URLs
RewriteRule ^about/$ /about.php [L]
我已经保存了它,但它没有在我的网站上重写它。它仍然显示“丑陋”的网址。我不知道该怎么做,因为我对 htaccess 文件还很陌生,并且不确定为什么它不起作用。
如果我输入“漂亮”网址 (www.mommy-info.com/about/),它没有 CSS,但它是漂亮网址。如果我浏览网站上的菜单,它只会显示丑陋的网址。
最佳答案
当我访问您的网站时,似乎mod_rewrite正在工作,事情有点不对劲。
是否打中
http://www.mommy-info.com/about.php
或
http://www.mommy-info.com/about/
我看到了相同的内容,
这可以通过
看到$ curl http://www.mommy-info.com/about/ | md5
1105b8f6dbf1a2c52bddd8e5f9046653
$ curl http://www.mommy-info.com/about.php | md5
1105b8f6dbf1a2c52bddd8e5f9046653
这里的问题实际上似乎与您的 main.css
资源有关,该资源被引用为:
<link href="main.css" type="text/css" rel="stylesheet"/>
问题是我请求/about/
时,相对引用了css文件,失败;您可以通过在浏览器中检查并刷新 /about/
页面来看到这一点,样式表将抛出 404。
$ curl --head http://www.mommy-info.com/about/main.css
HTTP/1.1 404 Not Found
要解决样式表问题,请更改代码行以从文档根目录访问它,方法是在路径前面添加 /
,这将访问它 statically vs relatively .
<link href="/main.css" type="text/css" rel="stylesheet"/>
/\ access statically from root
除了样式表之外,您可能希望从 RewriteRules 中删除所有尾部斜杠,因为它会强制用户附加 /
或 404将会看到:
$ curl --head http://www.mommy-info.com/about
HTTP/1.1 404 Not Found
$ curl --head http://www.mommy-info.com/about/
HTTP/1.1 200 OK
关于php - 为什么我的 .htaccess 文件在 cPanel 中无法工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43418786/