php - 重叠 htaccess 命令?
问题描述
问题是第一个重写规则是允许我的推荐值使用隐藏在链接中的 php 扩展名。
例如。mylink.com/myref
status.php是一个不同的页面,但是,如果我输入 mylink.com/status 它只是直接进入索引。我也希望 status.php 的 php 也被隐藏。重叠重写规则的最佳解决方案是什么?
编码 :
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?str=$1
RewriteRule ^status$ status.php [L]
解决方案
我相信在我的示例之后,您将对此有详细的了解...只需复制并尝试了解此...
创建一个项目文件夹,然后创建一个.htaccess文件,user.php,index.php,test.php
然后复制下面的代码...... 在.htaccess文件中
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteRule ^test?$ test.php
RewriteRule ^user?$ user.php
RewriteRule ^user/([0-9]+)$ user.php?id=$1
RewriteRule ^game/(1)? http://triviamaker.com [R=301,L]
在user.php文件中
<?php
if(isset($_GET['id'])){
echo "User Id :".$_GET['id'];
}else{
echo "<h3>Opps write localhost/user/anynumber</h3>";
}
?>
在index.php文件中
<?php
echo "Hello World";
?>
在test.php文件中
<?php
echo $temp = $_GET['land'];
echo $temp = $_SERVER['QUERY_STRING'];
if($temp == "1" || $temp == "land=1"){
header('Location: https://example.com');
}else if($temp == "2" || $temp == "land=2"){
header('Location: https://gmail.com');
}else if($temp == "3" || $temp == "land=3"){
header('Location: https://apple.com');
}else if($temp == "4" || $temp == "land=4"){
header('Location: user/2');
}
?>
现在运行这个文件:
- 本地主机/ your_project_folder_name /
- 本地主机/_your_project_folder_name/用户
- localhost/_your_project_folder_name/user.php
& 也使用这样的参数运行
- localhost/_your_project_folder_name/用户/1
- 本地主机/_your_project_folder_name/用户/2
- localhost/_your_project_folder_name/test?2
- localhost/_your_project_folder_name/test?3
- 本地主机/_your_project_folder_name/游戏/1
我希望通过这个例子你可以轻松理解不同的场景......谢谢