对.htaccess中的特定文件名执行If语句

编程入门 行业动态 更新时间:2024-10-23 16:21:17
本文介绍了对.htaccess中的特定文件名执行If语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个重写规则,但是我希望重写规则仅在页面不是index.php时才运行,我尝试使用If语句,但无济于事。我的代码,我尝试过的。

I have a Rewrite rule but i want the rewrite rule to only run when the page is not index.php, I have tried using If statement, all but no avail. My code, what I have tried.

Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^index$ ./index.php // i did a URL rewrite for removing the .php <If "%{HTTP_HOST } == 'index'"> // do nothing here else </If> <Else> //run the code in the else statement. RewriteRule ^ profile.php [NC,L] RewriteRule ^profile/([0-9a-zA-Z]+) profile.php?id=$1 [NC,L] RewriteRule ^ zprofile.php [NC,L] RewriteRule ^zprofile/([0-9a-zA-Z]+) zprofile.php?id=$1 [NC,L] </Else>

推荐答案

我在缺乏光泽的夜晚解决了这个问题,下面的简单代码,但是我使用了另一种方法,而不是使用if语句,我只是重写了我首先知道目录中位置的页面,因此目录中不存在的任何页面都应使用url重定向到特定页面

I solved it after a lack lustre night, with this simple code below, but I did it with another approach, instead of use if statement, i simply rewrote the pages i knew where on my directory first so any page that does not exist on my directory should be redirected to a particular page with the url being the same.

Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^zindex$ zindex.php //file in the directory RewriteRule ^index$ index.php //file in the directory RewriteRule ^zprofile$ zprofile.php //file in the directory RewriteRule ^logout logout.php [NC] //file in the directory RewriteCond %{REQUEST_FILENAME} !-f //if file does not exist in directory redirect RewriteCond %{REQUEST_FILENAME} !-d //if file does not exist in directory redirect RewriteRule ^.*$ profile.php [L] //to profile.php page with the URL still being the same.

更多推荐

对.htaccess中的特定文件名执行If语句

本文发布于:2023-10-31 19:02:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名   语句   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!