【问题标题】:Htaccess error with capturing get variables AND trailing slash捕获获取变量和斜杠时出现 Htaccess 错误
【发布时间】:2012-03-21 18:39:59
【问题描述】:

我的 .htaccess 文件中有以下内容

    # Use PHP5 Single php.ini as default
    AddHandler application/x-httpd-php5s .php

    Options -Indexes


    # preserve bandwidth for PHP enabled servers
    <ifmodule mod_php4.c>
     php_value zlib.output_compression 16386
    </ifmodule>

    # For security reasons, Option followsymlinks cannot be overridden.
    #Options +FollowSymLinks
    Options +SymLinksIfOwnerMatch
    RewriteEngine On
    RewriteRule ^faq/?$ faq.php
    RewriteRule ^about/?$ about.php
    RewriteRule ^portfolio/(.*)$ portfolio.php?p=$1

            #Error Page___NOT found
    ErrorDocument 404 /notfound.php

我的作品集仅包含“名人”、“婚礼”和“工业”部分 即只有以下页面是有效的投资组合:

    mysite.com/portfolio/celebrity
    mysite.com/portfolio/weddings
    mysite.com/portfolio/industrial

在某些情况下,我的“作品集”页面出现问题:当我访问时

    "mysite.com/portfolio/celebrity"
    "mysite.com/portfolio/weddings"
    "mysite.com/portfolio/industrial"

一切正常。但是,如果我访问

    "mysite.com/portfolio/celebrity/"
    "mysite.com/portfolio/weddings/"
    "mysite.com/portfolio/industrial/"

(注意尾部斜杠),Firefox 给我以下错误

    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

我尝试用

替换最后一行
    RewriteRule ^portfolio/(.*)/?$ portfolio.php?p=$1

这也无济于事,并显示上述错误。

参观

    "mysite.com/portfolio/some-non-existent-portfolio"

    "mysite.com/portfolio/some-non-existent-portfolio/"

不重定向到“notfound.php”

【问题讨论】:

  • 尝试添加Options -MultiViews
  • 不,这并不能解决问题......还有其他想法吗?

标签: .htaccess url-rewriting slash


【解决方案1】:

好的,感谢这个网页: http://www.phpfreaks.com/forums/index.php?topic=167839.0

我将相关行改为

    RewriteRule ^portfolio/([a-zA-Z]+)/?$ portfolio.php?p=$1

现在一切正常,包括在访问的投资组合类型不存在时显示“notfound.php”。希望这对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-09
    • 2020-03-27
    • 1970-01-01
    • 2014-02-19
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多