【问题标题】:htaccess redirecting loop with browserhtaccess 使用浏览器重定向循环
【发布时间】:2014-10-23 12:17:25
【问题描述】:
<ifModule mod_rewrite.c>
ErrorDocument 404 /notfound.html
RewriteEngine On
Options +FollowSymLinks -Indexes -MultiViews
RewriteBase /

RewriteRule ^(gateway)($|/) - [L]
RewriteRule ^(inc)($|/) - [L]

# make sure it's not a directory or a file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# match out the request URI without the trailing slash
RewriteCond %{REQUEST_URI} ^/([^/]+?)/?$
# and see if it exists
RewriteCond %{DOCUMENT_ROOT}/%1.php -f

RewriteRule ^(.+?)/?$ /$1.php [L]

RewriteCond %{REQUEST_METHOD} !POST [NC]
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+?)\.php
RewriteRule ^(.+?)\.php$ /$1 [L,R=301]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]


RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index.php\?id=([a-z0-9]+)&num=([a-z0-9]+) [NC]
RewriteRule ^ %1/%2/ [R=301,L,NC]
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ /index.php?id=$1&num=$2 [L,NC]

</ifModule>

大家好, 我在使用 htaccess 时遇到问题。浏览器仍然警告此网页有重定向循环 我找到了更多解决方案,但我无法修复它:( 我试图重写/重定向 *.php 到目录示例 index.php 到 /index 我想将 url index.php?id=read&num=11233445667 重写为 /read/11233445667

成功了。但仍然“这个网页有一个重定向循环”:(

请帮我修复上面的 htaccess。非常感谢!

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    你需要放置最后一条规则:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index.php\?id=([a-z0-9]+)&num=([a-z0-9]+) [NC]
    RewriteRule ^ %1/%2/ [R=301,L,NC]
    RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ /index.php?id=$1&num=$2 [L,NC]
    

    靠近顶部(RewriteRule ^(inc)($|/) - [L] 下方)

    这样它就不会干扰更通用的 php 扩展规则。您可能还应该在内部重写中添加条件:

    RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ /index.php?id=$1&num=$2 [L,NC]
    

    到:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ /index.php?id=$1&num=$2 [L,NC]
    

    【讨论】:

    • 亲爱的,我在 index.php 文件中发现了问题。因为我在会话超时时设置了重定向。所以我用 session_destroy 替换它并且它工作正常。所以你的解决方案仍然可以正常工作。谢谢你:)
    猜你喜欢
    • 2015-10-09
    • 1970-01-01
    • 2022-01-23
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多