HT访问无限循环时通过索引.php重定向所有内容



我环顾四周寻找解决方案,没有发现任何东西可以阻止我的无限循环问题。

我对htaccess很陌生,所以请原谅我..

目前正在为我正在构建的 CMS 运行 WAMP 服务器,我想通过 index.php 文件重定向所有页面请求,例如 localhost/cms/pageName,同时保持 URL 不变。

#disable directory showing
Options -Indexes 
#error documents
ErrorDocument 404 cms/html/notfound.html
ErrorDocument 403 cms/html/notfound.html
#index
DirectoryIndex cms/html/index.php
RewriteEngine On 
Options +FollowSymlinks
RewriteBase /
RewriteRule ^admin/?$ cms/html/login.php
RewriteRule ^login.php?$ cms/php/login.php
RewriteRule ^reset_password?$ cms/html/reset_password.php
RewriteRule ^reset.php/?$ cms/php/reset.php
RewriteRule ^reset_action.php/?$ cms/php/reset_action.php
# Internally redirect all pages to index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . cms/index.php/$1?%{QUERY_STRING} [L]

无论出于何种原因,重定向时它都会再次重定向,我不知道为什么..

很容易用

错误的".htaccess"文件完全崩溃其服务器,甚至包含一个语法错误。如果出现错误,只需重命名或删除文件

我认为问题来自点后面的空格:

RewriteRule . cms/index.php/$1?%{QUERY_STRING} [L]

.

我不明白你为什么需要这样做,我告诉你你也可以模拟网址重写

在您的 .htaccess 文件中,您需要编写以下行:

errordocument 404 /index.php

在你的 index.php 文件中,你可以编写这个来模拟 URL 重写:

$url = $_SERVER['REQUEST_URI'];
$url=substr($url,1,strlen($url));  // The page url that gave an error 404
echo $url;

接下来,如果需要,您可以创建给出 404 错误的页面并将用户重定向到该页面

$handle = fopen($url.'/index.html', 'w');
fwrite($handle, 'hello world');
fclose($handle);
header('location:'.$url);
exit;

最新更新