我的.htaccess文件遇到了问题.
该文件将难看的URL(如http://localhost/news.php?article_slug=example-1
)更改为http://localhost/news/example-1
这可以完美地工作,但是当我使用http://localhost/news
时,我得到一个404错误.
在news.php中,我有一个重定向;因此,如果URL中没有文章段,它将重定向到latest.php.
我在news.php上的PHP代码
$article_slug=$_GET['article_slug'];
if (empty($_GET)) {
header("Location: ../latest.php");
die();// no data passed by get
}
这是我当前在我的.htaccsess文件中拥有的内容
Options -MultiViews
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteRule ^news/([\w\d-]+)$ /news.php?article_slug=$1[QSA,L]
RewriteCond %{QUERY_STRING} article_slug=([\w\d-]+)
RewriteRule ^news$ /news/%1 [R,L]
RewriteRule ^category/([\w-]+)$ /category.php?category_slug=$1&page=$2 [QSA]
当我自己try 调试它时,(with very little knowledge)并添加以下代码行,它重定向到latest.php
RewriteRule ^([^/]*)/?$ /news.php [L,QSA]
但是在重定向的页面上,我得到了以下错误
The page isn’t redirecting properly
Firefox has detected that the server is redirecting the request for this
address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept cookies
当我以IMSoP的身份使用Firefox中的开发人员工具时,我看到的只是多次重新加载了Latest.php.
这不仅隔离到latest.php,而且还隔离到服务器上未在Access文件中列出的任何文件
当我删除这行时
RewriteRule ^([^/]*)/?$ /news.php [L,QSA]
我可以加载PHP文件,但它不能从news.php重定向,并且找不到http://localhost/news
,但http://localhost/news/example-1
可以工作.