0

我想重定向这个

http://www.domain.com/test.php?sub=subdomain&type=cars

重定向到

http://subdomain.domain.com/cars

我已经有 mod_rewrite 规则来做相反的事情:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
RewriteRule (.*) http://www.%2.com/index.php?route=$1&name=%1 [R=301,L]

使用htaccess,请帮助我...

4

2 回答 2

0

You could test this, tested today, by adding ? at the end to suppress ${QUERY_STRING} from the returned URL after rewriting:

RewriteCond %{QUERY_STRING} sub=([^&]+)&type=([^&]+)
RewriteRule ^test\.php$ http://%1.domain.com/%2? [R=301,L]

%{QUERY_STRING} is parsed for the parameters %1 and %2 from RewriteCond.

Test:

http://www.domain.com/test.php?sub=subdomain&type=cars

Redirected to:

http://subdomain.domain.com/cars

The rewrite rules are tested in the vhosts file or equivalent for apache2 server configuration, and also in .htaccess file, in the latter case one must suppress the root directory slash /.

于 2013-10-16T22:49:13.880 回答
0

你可能想要这样的东西:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
RewriteRule (.*) /index.php?route=$1&name=%1 [L]

# then the redirect
RewriteCond %{THE_REQUEST} \ /index\.php\?route=([^&]+)&name=([^&\ ]+)
RewriteRule ^ http://%2.domain.com/%1 [L,R=301]
于 2013-10-16T23:46:22.877 回答