-1

我正在尝试将所有请求从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]

为什么不发生重定向?

4

1 回答 1

1

试试这个,让我知道它是否有效。如果没有,请让我知道哪个 URL 不起作用。

<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>
于 2013-03-02T23:58:56.013 回答