.htaccess重定向子目录下的所有子目录

时间:2013-09-04 13:20:14

标签: .htaccess

我想将子目录root/windows/下的所有子目录重定向到root/windows/ct.php

网站的文件结构就像

root/windows/ct.php

重定向这些类型的网址

http://www.site.com/windows/games/ or http://www.site.com/windows/games
http://www.site.com/windows/software/ or http://www.site.com/windows/software

http://www.site.com/windows/ct.php?ct=games
http://www.site.com/windows/ct.php?ct=software

我正在尝试这样但它会将所有网址重定向到子目录root/windows/ct.php

RewriteRule ^([^/]*)/ /Site/windows/?ct=$1 [L]
RewriteRule ^([^/windows]*)/ /Site/windows/?ct=$1 [L] // this one shows internal server error

完成.htaccess代码

Options +FollowSymlinks
RewriteEngine on

<IfModule mod_rewrite.c>
RewriteRule ^(error) - [L]
RewriteRule ^[^/]*/[^/]*/(.*\.html) /Site/error/400/ [L]
RewriteRule ^([^/]*)/(.*\.html) /Site/software/?link=$1&id=$2 [L]
RewriteRule ^([^/]*)/ /Site/windows/?ct=$1 [L]
RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteRule ^rss/(.*?)\.xml$ rss/$1.php [L]
</IfModule>

ErrorDocument 400 /Site/error/400/

我不太清楚.htaccess请查看并建议任何可行的方法。 感谢。

1 个答案:

答案 0 :(得分:4)

尝试一下:

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^windows/([^/]+)/?$ /windows/ct.php?ct=$1 [L]
</IfModule>

对于localhost使用此内容:

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /Site/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^windows/([^/]+)/?$ windows/ct.php?ct=$1 [NC,L]
</IfModule>