3

我想将子目录下的所有子目录重定向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/

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

4

1 回答 1

3

试试这个:

<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>
于 2013-09-04T13:23:57.783 回答