0

我需要使用以下条件制定一些重写规则以包含在 .htaccess 中:

(www).site.com/setup   --> redirects to: www.site.com/setup
demo.site.com/setup    --> redirects to: www.site.com/demo/setup
(www).site.com/xyz   --> redirects to: www.site.com/web/xyz
demo.site.com/xyz    --> redirects to: www.site.com/demo/web/xyz

请注意,(www) 表示用户既可以输入也可以不输入 www,“xyz”可以是任何字符串,但不同于关键字“setup”(由于前两个规则)。

这是我尝试过的(使用 [L] 进行例外处理),但我不确定它是否足够好:

RewriteCond ${REQUEST_URI} demo.
RewriteCond ${REQUEST_URI} /setup
RewriteRule /demo/setup [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond ${REQUEST_URI} /setup
RewriteRule /setup [L]

RewriteCond ${REQUEST_URI} demo.
RewriteRule ^/(.*)$ www.site.com/demo/web/$1 [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^/(.*)$ www.site.com/web/$1 [L]

有任何想法吗?

卢西亚诺

4

1 回答 1

0

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(demo)\.(.+)$ [NC]
RewriteRule ^(setup)/?$ http://www.%2/%1/$1 [L,R=301,NC]

RewriteCond %{HTTP_HOST} ^(demo)\.(.+)$ [NC]
RewriteRule ^(xyz)/?$ http://www.%2/%1/web/$1 [L,R=301,NC]

RewriteCond %{HTTP_HOST} !^demo\. [NC]
RewriteRule ^(xyz)/?$ /web/$1 [L,R=301,NC]
于 2013-07-08T21:25:09.133 回答