使用mod_rewrite问题重定向

时间:2013-03-02 23:26:32

标签: apache mod-rewrite

我正在尝试重定向来自domain.com/sign-up/*的所有请求。到domain.com/sign-up/ 另外,我想知道我的代码是否可以改进,见下文。

Options +FollowSymLinks  
Options +Indexes  
RewriteEngine On
RewriteRule ^sign-up/(.*)\.php$ public/register.php [NC] 
RewriteRule ^sign-up/(.*) /sign-up/ [R]
RewriteRule ^sign-up/\??lang=([a-zA-Z][a-zA-Z][a-zA-Z])$ public/register.php?lang=$1 [NC]
RewriteRule ^sign-up/?$ public/register.php [NC,L]

为什么不进行重定向?

1 个答案:

答案 0 :(得分:1)

试试这个,让我知道它是否有效。如果没有,请告诉我哪个网址无效。

<IfModule mod_rewrite.c>
Options +FollowSymLinks  
Options +Indexes  
RewriteEngine On
RewriteBase /

# sign-up/xxx.php -> public/register.php
RewriteRule ^sign-up/.*\.php$ public/register.php [L] 

# sign-up/xxx -> /sign-up/
RewriteRule ^sign-up/.+ /sign-up/ [R=301,QSA,L]

# sign-up/?lang=xxx -> public/register.php?lang=xxx
RewriteCond %{QUERY_STRING} .*lang=([a-z]{3}).* [NC]
RewriteRule ^sign-up/$ public/register.php?lang=%1 [L,NC]

# /sign-up/ -> public/register.php
RewriteRule ^sign-up/?$ public/register.php [NC,L]
</IfModule>