Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php url重写在一个.com提供程序上不起作用_Php_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php url重写在一个.com提供程序上不起作用

Php url重写在一个.com提供程序上不起作用,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,目前,我正试图让url重写工作在一个.com托管提供商,这是一个痛苦和支持不理解的问题,所以我想在这里问一下,你是否可以帮助我找到这个问题 我使用的重写规则适用于localhost,但不适用于提供程序: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^\.]+)$ $1.p

目前,我正试图让url重写工作在一个.com托管提供商,这是一个痛苦和支持不理解的问题,所以我想在这里问一下,你是否可以帮助我找到这个问题

我使用的重写规则适用于localhost,但不适用于提供程序:

<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]
然后在post.php ofc中,我使用
seo GET变量
在页面上显示帖子内容

完整的url
www.mysite.com/post/test

我最后得到的错误是404

Not Found

The requested URL /post/test-test-test.php was not found on this server.
因此,基本上我理解的是,它试图进入一个名为
/post/
的文件夹,并查找文件
test.php


因此,我认为它不包括重写规则,或者您能在本地主机上工作的重写规则中找到错误吗?

您需要重新排列规则,并且要添加
.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>

重新启动发动机
重写基/
RewriteCond%{HTTP_HOST}^mysite\.com$[NC]
重写规则^(.*)$http://www.%{HTTP_HOST}/$1[R=301,L,NE]
#忽略文件和目录的其余规则
RewriteCond%{REQUEST_FILENAME}-f[或]
RewriteCond%{REQUEST_FILENAME}-d
重写规则^-[L]
重写规则^([\w-]+)/?$index.php?key=$1[L,QSA]
重写规则^([\w-]+)/([\w-]+)/?$index.php?key=$1&seo=$2[L,QSA]
RewriteCond%{DOCUMENT_ROOT}/$1\.php-f[NC]
重写规则^(+?)/?$$1.php[L]

您的.htaccess中有更多的规则吗?您的假设是正确的,没有进行重写,因为这将表明在此服务器上找不到
index.php
否则。有关详细信息,请参阅。@anubhava我已更新了question@Sumurai8该站点似乎要在您可以访问服务器的本地主机上启用它。我试图让它在我的主机提供商上工作,而我根本无法访问服务器。然后按照不需要访问httpd.conf的步骤进行操作,看看它是否工作。如果没有,你必须联系你的主机提供商。
<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>