【发布时间】:2014-10-18 02:25:22
【问题描述】:
目前我正在尝试在 one.com 托管服务提供商上进行 url 重写,这很痛苦,支持不理解这个问题,所以我想在这里问你是否可以帮助我找到问题。
我正在使用这个重写器,它在本地主机上工作,但不是在提供程序上工作:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?key=$1&seo=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?key=$1&seo=$2
</IfModule>
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^(.*)$ http://www\.mysite.com/$1 [R=permanent,L]
并在索引中:
if($key=='post') //Cant include $seo here because the variable differ for
//each post on the site
{
include('post.php'); // Post page
}
然后在 post.php ofc 中,我使用seo GET variable 在页面上显示帖子内容。
完整网址www.mysite.com/post/test-test-test
我最终得到的错误是 404
Not Found
The requested URL /post/test-test-test.php was not found on this server.
所以基本上我的理解是它试图进入一个名为/post/ 的文件夹并查找文件test-test-test.php
所以我相信它不包括重写规则,或者你能在本地主机上工作的重写规则中找到错误吗?
【问题讨论】:
-
您的 .htaccess 中有更多规则吗?
-
假设没有重写是正确的,否则它会显示
index.php was not found on this server。请参阅stackoverflow.com/questions/869092/… 了解更多信息。 -
@anubhava 我已经更新了问题
-
@Sumurai8 该站点似乎是关于在您可以访问服务器的本地主机上启用它。我正试图让它在我根本无法访问服务器的托管服务提供商上工作。
-
然后按照不需要访问httpd.conf的步骤,看看是否有效。如果没有,您必须联系您的托管服务提供商。
标签: php apache .htaccess mod-rewrite url-rewriting