首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用$_get函数重写htaccess URL

问使用$_get函数重写htaccess URL
EN

Stack Overflow用户
提问于 2013-08-10 01:22:28
回答 1查看 413关注 0票数 0

我一直在尝试为一个网站做一个htaccess URL重写(R=302),该网站使用$_get函数通过字符串来拉取内容页面。例如,我正在尝试更改以下内容:

http://www.site.com/index.php?page=about

如下所示:

http://www.site.com/about/

但是,我已经设法将其设置为,如果我使用查询第二个URL,它将重定向index.php文件中的页眉和页脚数据,但它不会获取内容的CSS或$_get信息。以下是htaccess条目和$_get信息:

代码语言:javascript
复制
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代码,但没有成功,认为这就是问题所在。

EN

回答 1

Stack Overflow用户

发布于 2013-08-10 04:56:31

首先,您的两个重写规则具有相同的条件,因此只会满足第一个重写规则。我认为您可能只想在服务器上不存在所请求的uri时重写。

代码语言:javascript
复制
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/?$ /index.php?x=$1 [L]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18152264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档