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



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

站点的文件结构类似

root/windows/ct.php

重定向这些类型的url

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

我尝试这样做,但它将所有url重定向到子目录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/

我不太了解。访问请查看并建议任何可能的方法。谢谢

尝试一下:

<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>

最新更新