【问题标题】:.htaccess redirect all sub directories under sub directory.htaccess 重定向子目录下的所有子目录
【发布时间】:2013-09-04 21:38:22
【问题描述】:

我想将子目录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 请查看并建议任何可能的方法。 谢谢。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • @TallboY 删除所有旧的 .htaccess 并像上面一样使用这个
    • +1 这应该可以。 @TallboY:跟踪你的 apache 错误日志,看看那里有什么错误。
    • @anubhava [Wed Sep 04 18:58:03.913148 2013] [core:error] [pid 1748:tid 1548] [client 127.0.0.1:52441] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
    • @TallboY 您是否删除了旧的 .htaccess 并单独尝试了上述方法?
    • @TallboY 在测试新规则时最好使用 302 而不是 301,以避免缓存结果,直到它按您希望的方式工作。如果答案解决了您的问题,请标记它:)
    猜你喜欢
    • 2010-12-09
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    相关资源
    最近更新 更多