1

我想使用 将子目录重定向到子域.htaccess。我当前的代码:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^(www.)?sub.example.com$
RewriteRule ^(/)?$ subdirectory [L]
</IfModule>

此代码重定向到sub.example.com/subdirectory. 如何/subdirectory从新 URL 中删除?

4

1 回答 1

2

将此规则放在最上面,在所有其他规则之前:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^subdirectory/(.*)$ http://www.sub.example.com/$1 [L,NC,R=301]

完成.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^subdirectory/(.*)$ http://sub.example.com/$1 [L,NC,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?sub\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !(jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteRule !subdirectory subdirectory%{REQUEST_URI} [NC,L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
于 2013-10-24T12:42:25.800 回答