我一直在尝试为一个网站做一个htaccess URL重写(R=302),该网站使用$_get函数通过字符串来拉取内容页面。例如,我正在尝试更改以下内容:
http://www.site.com/index.php?page=about
如下所示:
但是,我已经设法将其设置为,如果我使用查询第二个URL,它将重定向index.php文件中的页眉和页脚数据,但它不会获取内容的CSS或$_get信息。以下是htaccess条目和$_get信息:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*?)/$ /index.php?page=$1 [NC,QSA,L]
RewriteRule ^(.*?)/$ $1.html [NC,L,QSA,R=302]
<?php
$folder = '';
$ext = 'html';
if (!$_GET['page'] || strpos($_GET['page'], '/') === true)
$path = 'home.' . $ext;
else $path = $_GET['page'] . '.' . $ext;
if (!file_exists($path)) {
$messages = array(
'404: Page does not exist; Please check the URL you entered.',
'404: Error 404, please check the URL of the page.'
);
print $messages[ rand(0, (count($messages) - 1)) ];
}
elseif (!@include($path)) print '300: couldn\'t get the page';
?>任何帮助都将不胜感激。我一直在尝试修改php代码,但没有成功,认为这就是问题所在。
发布于 2013-08-10 04:56:31
首先,您的两个重写规则具有相同的条件,因此只会满足第一个重写规则。我认为您可能只想在服务器上不存在所请求的uri时重写。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/?$ /index.php?x=$1 [L]https://stackoverflow.com/questions/18152264
复制相似问题