我正在使用mod-rewrite来制作我的网址,这些网址确实是
www.example.com/public/questions.php?question_id= <int>
转到
www.example.com/questions/ <int>
然后如何禁止以前的地址用作REQUEST_URI,并只允许他们通过我新的缩短网址?
如果我放一个规则
RewriteRule ^public public/page404_ready.php
这也使我当前更改的所有 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]