Php .htaccess未在webhost上正确重定向

Php .htaccess未在webhost上正确重定向,php,.htaccess,Php,.htaccess,我有一个网站,这是.htaccess文件: DirectoryIndex home.php index.php RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule home home.php RewriteRule ^pages/([^\.]+)$ $1.php RewriteRule ^news-list/([^\.]+)$ news-lis

我有一个网站,这是.htaccess文件:

DirectoryIndex home.php index.php
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule home home.php

RewriteRule ^pages/([^\.]+)$ $1.php
RewriteRule ^news-list/([^\.]+)$ news-list.php?id=$1
RewriteRule ^iq-admin/([^\.]+)$ iq-admin/$1.php
RewriteRule ^news/([0-9]+)/([A-Za-z0-9-]+)/?$ latest-news.php?id=$1&post=$2 [NC,L]
RewriteRule ^events-list/([^\.]+)$ events-list.php?id=$1
RewriteRule ^events/([0-9]+)/([A-Za-z0-9-]+)/?$ upcoming-events.php?id=$1&post=$2 [NC,L]

当我点击时,它说这是一个重定向循环,但在本地主机上运行良好。请帮帮我。

我可以看到一些潜在的陷阱,但我认为这是你的罪魁祸首

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule home home.php
您可能希望确保
home
是一个完整的短语,并相对于文档根进行重定向,如下所示:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home/?$ /home.php
使用像
/news list/home
这样的URL,将命中第一个匹配项并尝试重定向到
/news list/home.php
,我假设它不存在,所以它将尝试(再次)重定向到
/news list/home.php
,等等


您可能应该更新所有重定向,使其与docroot相对。

您需要将这一行放在.htaccess的顶部:

Options -MultiViews

选项
MultiViews
Apache的内容协商模块使用,该模块在
mod_rewrite
之前运行,并使Apache服务器匹配文件扩展名。所以
/file
可以在URL中,但它将提供
/file.php

/news list/
目录中是否有.htaccess?@CD001出于某种神秘的原因,它在本地主机上运行良好。在web主机上,它被重定向到
http://alburoojschool.org/news-list/home
尽管它没有被重定向到htaccess或href链接中的新闻列表/主页的任何位置。(如果可以的话,你可以参考网站)@anubhava no.htaccess文件在基本目录中。在news list.php中有任何重定向吗?对不起,有重定向
if(!isset($\u GET['id']){header(“home”);
}`我已经更改为
if(!isset($\u GET['id']){header(“位置:http://alburoojschool.org);}
。但现在它被重定向到home,这意味着它没有获得
?id=$1
。但它能够在localhost中运行。知道为什么吗?