1

我正在使用 mod-rewrite 来制作真正的网址

www.example.com/public/questions.php?question_id= <int>

www.example.com/questions/ <int>

那么怎么可能禁止以前的地址用作 REQUEST_URI 并只允许它们通过我的新缩短的 url?

如果我提出一个规则

RewriteRule ^public public/page404_ready.php

这也使我当前更改的所有网址都没用。


(如果我确实完成了这一切,我是否必须将页面中所有我自己的(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]
4

1 回答 1

3

我不明白你到底想用这个规则做什么:

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]
于 2012-06-06T12:45:52.490 回答