【问题标题】:url rewriting not working on one.com providerurl 重写在 one.com 提供商上不起作用
【发布时间】: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


【解决方案1】:

您需要重新排列规则并添加 .php 扩展名,确保存在带有 .php 的文件:

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NE]

# ignore rest of the rules for files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([\w-]+)/?$ index.php?key=$1 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?key=$1&seo=$2 [L,QSA]

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

</IfModule>

【讨论】:

    猜你喜欢
    • 2012-12-23
    • 2013-12-16
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 2016-12-18
    相关资源
    最近更新 更多