Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 不使用$u get[';page';]进行mod#u rewrite_Php_.htaccess - Fatal编程技术网

Php 不使用$u get[';page';]进行mod#u rewrite

Php 不使用$u get[';page';]进行mod#u rewrite,php,.htaccess,Php,.htaccess,我目前的链接是: domain.com/folder/index.php?page=home 我试图做到这一点: domain.com/folder/home 我用来获取页面的PHP代码 <?php if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 'home'; } if (strpos($page, '/') !== false || !file_exists("pages/$page.php")

我目前的链接是:

domain.com/folder/index.php?page=home
我试图做到这一点:

domain.com/folder/home
我用来获取页面的PHP代码

<?php
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 'home';
}
if (strpos($page, '/') !== false || !file_exists("pages/$page.php")) {
$page = 'error';
}
include ("pages/$page.php");
?>

为了得到正确的.htaccess代码,我做了很多努力来重写我的URL,从生成器到论坛帖子,但我找不到正确的代码。


我希望有人能帮我找到正确的方向,让这项工作顺利进行。

这些
。htaccess
规则应该可以帮助您开始

RewriteEngine On
RewriteBase /

#### this allows you to write your links in the form /folder/home ####
RewriteRule ^folder/([0-9]+)$ folder/index.php?page=$1 [NC,L]


#### to dynamically redirect to /folder/home ####
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?page=([^&\s]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]

这些
.htaccess
规则应该可以帮助您开始

RewriteEngine On
RewriteBase /

#### this allows you to write your links in the form /folder/home ####
RewriteRule ^folder/([0-9]+)$ folder/index.php?page=$1 [NC,L]


#### to dynamically redirect to /folder/home ####
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?page=([^&\s]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
在您的htaccess中利用此功能


在您的htaccess中利用此功能

我建议您发布您的http主机配置和
.htaccess
样式文件的内容,以便我们提供帮助。我们对你发布的基于php的路由器不感兴趣…发布你的htaccess。如果没有它,我们真的无法提供帮助。“我当前的链接是”-您需要在应用程序中更改这些链接,如果您还没有更改的话。我建议您发布您的http主机配置和
.htaccess
样式文件的内容,以便我们提供帮助。我们对你发布的基于php的路由器不感兴趣…发布你的htaccess。没有它我们真的帮不上忙。“我当前的链接是”-如果你还没有更改应用程序中的这些链接,你需要更改。不!无法在Redirect指令中处理查询字符串。请注意,Rediret指令不支持正则表达式,如果与支持正则表达式的RedirectMatch一起使用,您的EDID代码将在服务器上导致重定向循环错误。解决OP问题的更好方法是mod_rewrite.No!无法在Redirect指令中处理查询字符串。请注意,Rediret指令不支持正则表达式,如果与支持正则表达式的RedirectMatch一起使用,您的EDID代码将在服务器上导致重定向循环错误。解决OP问题的更好方法是mod_重写。