Php 如何阻止人们访问正常路径,但允许在Mod Rewrite中使用它
我正在使用mod rewrite使我的URLPhp 如何阻止人们访问正常路径,但允许在Mod Rewrite中使用它,php,.htaccess,url,mod-rewrite,Php,.htaccess,Url,Mod Rewrite,我正在使用mod rewrite使我的URL www.example.com/public/questions.php?question_id= <int> 这使得我所有当前更改的URL也变得毫无用处 (如果我完成了所有这些,我是否必须将页面中所有我自己的(AJAX)链接更改为新URL?) 这是我目前的档案 RewriteRule ^questions/topics/(.+)/?$ public/questions.php?topics=$1 [NC,L] RewriteRule
www.example.com/public/questions.php?question_id= <int>
这使得我所有当前更改的URL也变得毫无用处
(如果我完成了所有这些,我是否必须将页面中所有我自己的(AJAX)链接更改为新URL?) 这是我目前的档案
RewriteRule ^questions/topics/(.+)/?$ public/questions.php?topics=$1 [NC,L]
RewriteRule ^questions/ask/?$ public/ask_question.php [NC,L]
RewriteRule ^questions/edit/([0-9]+)/?$ public/edit_question.php?question_id=$1 [NC,L]
RewriteRule ^questions/posts/edit/([0-9]+)/?$ public/edit_post.php?post_id=$1 [NC,L]
RewriteRule ^users/edit/([0-9]+)/?$ public/edit_profile.php?user_id=$1 [NC,L]
RewriteRule ^(admin)/?$ public/$1/index.php [NC,L]
RewriteRule ^(admin)/(\w+)/?$ public/$1/$2.php [NC,L]
RewriteRule ^(admin)/(\w+)/(\d+)/?$ public/$1/$2.php?topic_id=$3 [NC,L]
RewriteRule ^([\w\-]+)/?$ public/$1.php [NC,L]
#RewriteRule ^public public/page404_ready.php [L]
我不明白你到底想用这个规则做什么:
RewriteRule ^public public/page404_ready.php
您可以使用以下代码:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# this is your current rule
RewriteRule ^questions/([0-9]+)/?$ public/questions.php?question_id=$1 [L,NC,QSA]
# this is the URL you want to block
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+public/questions\.php\?question_id=[0-9]+[&\s] [NC]
RewriteRule ^ - [F]
(是的,你也需要更改所有链接和ajax URL)我不明白,我用我的文件更新了我的问题,如何阻止人们访问www.example.com/public/questions.php?question_id=?上面的第二条规则正是这样做的,即阻止人们访问
www.example.com/public/questions.php?question_id=
如果您将此规则放入.htaccess并访问该URI,您将得到禁止的错误。在我的php代码中这样做是否更好。。在所有那些只有输入正确url才会重定向的页面上,继续重定向回我自己的样式url?[A-Z]{3,}
基本上匹配HTTP方法,如GET、POST、PUT、DELETE等。与其编写代码,不如通过.htaccess本身处理此问题,这在未来的更改周期中很容易维护。哇,那真的很有帮助,谢谢。也许你能帮我理解为什么我的example.com/public页面有一个重定向循环?
RewriteRule ^public public/page404_ready.php
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# this is your current rule
RewriteRule ^questions/([0-9]+)/?$ public/questions.php?question_id=$1 [L,NC,QSA]
# this is the URL you want to block
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+public/questions\.php\?question_id=[0-9]+[&\s] [NC]
RewriteRule ^ - [F]