简体   繁体   English

使用RewriteRule名称.htaccess限制URL重定向

[英]restrict url redirecting using RewriteRule name .htaccess

i have check-login.php to prevent accessing the certain page using url but it doesn't work when i type the RewriteRule name 我有check-login.php以防止使用url访问特定页面,但是当我键入RewriteRule名称时它不起作用

example i type in the URL: domain/user-home.php , check-login.php works but when i type URL: domain/home check-login.php is not readable/working 例如,我输入URL: domain/user-home.php ,check-login.php起作用,但是当我键入URL: domain/home check-login.php不可读/不起作用

i used .htaccess to rewrite the name of my php file this is my code 我用.htaccess重写了我的php文件的名称,这是我的代码

RewriteRule ^home?$ user-home.php

my question is when i type RewriteRule name in URL restriction is not working which is my check-login.php, and it applies only on php file name like the mention above user-home.php 我的问题是,当我在URL限制中键入RewriteRule名称不起作用时,这是我的check-login.php,它仅适用于php文件名,如上面提到的user-home.php

check-login.php code: check-login.php代码:

session_start();
if(!$_SESSION['LOGIN'])
{
    exit(include('error2.php'));
}
// this code is included in user-home.php

I edited the code here. 我在这里编辑了代码。 Best approach would be like this. 最好的方法就是这样。

RewriteEngine on


RewriteCond %{REQUEST_METHOD} !^POST$
RewriteRule ^php/check-login.php$ - [NC,R=404,L]

this should redirect to the 404file not found . 这应该重定向到未找到的404file。

this is another way of doing things. 这是另一种做事方式。 you shoud have 404.php on the root directory. 您应该在根目录上有404.php。

RewriteRule ^404/?$ 404.php
ErrorDocument 404 http://www.example.com/404/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM