apache - 简单的 .htaccess RewriteRule 不起作用

标签 apache .htaccess mod-rewrite

不知道为什么这不起作用:

RewriteEngine On

RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteRule ^.+ http://example.com [L]
RewriteCond据我所知,正在工作。

对我来说,RewriteRule读到:
  • ^开始比赛
  • .+一个或多个字符

  • 然而,Firefox 44 告诉我

    The page isn't redirecting properly

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



    如果RewriteRule开始于 ^.* ,我希望服务器陷入无限循环。

    但是^.+应该工作,不是吗?

    最佳答案

    由于 DirectoryIndex,您正在接收重定向循环在 REQUEST_URI 中添加处理程序。

    要解决此问题,您可以使用以下规则:

    RewriteCond %{HTTP_HOST} www.localhost$ [NC]
    RewriteCond %{REQUEST_URI} !^/index\. [NC]
    RewriteRule ^.+ http://www.localhost [L,R]
    
    RewriteCond %{REQUEST_URI} !^/index\. [NC]将停止重定向循环,因为 /index.html/index.php通常是 DirectoryIndex处理程序。

    关于apache - 简单的 .htaccess RewriteRule 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35295647/

    相关文章:

    php - 从 apache 服务器中的 php 访问 shell 可执行文件

    php - .htaccess 在 Ubuntu Server x64 上不起作用

    apache - 使用 .htaccess 删除子目录中的尾部斜杠

    带身份验证的 Apache VirtualHost,websockets

    java - ubuntu 14.04 上的 apache hama 安装错误

    mysql - Apache:日志存储到 MySQL

    php - 安装 CakePHP。无法访问 Assets 。找不到样式。网址重写

    apache - htaccess : add path parameter (country code) to URL & serve index. html

    wordpress - 通过 .htaccess 重定向多个 URL

    php - 如何使用 php 为用户上传的文件设置自定义 url