【问题标题】:URL Rewrite in htaccess problemhtaccess 中的 URL 重写问题
【发布时间】:2010-04-29 16:40:01
【问题描述】:

我对这个 htaccess 重定向世界相当陌生。我试图将 Zend MVC 中的所有重定向强制到我的 https,但在未通过索引的请求上出现 requested URL not found 错误控制器

例子

https://www.example.com/auth/register

给出一个请求的 URL /auth/register 未找到错误。但是,如果我删除 https 重定向规则,它可以在 http 上正常工作。如果我将 URL 调整为

https://www.example.com/index.php/auth/register

它工作正常。 网址

https://www.example.com/index/faq 

工作得很好,因为它通过索引控制器。

我的 .htaccess 文件如下所示

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

获取网址需要做些什么调整

https://www.example.com/auth/register

工作吗?

【问题讨论】:

  • 发现了我的问题。我没有为通过端口 443 的 SSL 请求指定 mod-rewrite 规则。

标签: .htaccess mod-rewrite url-rewriting


【解决方案1】:

您的代码读作“如果这与文件、链接或目录匹配,则什么也不做并继续。”如果文件实际存在,则需要跳过最终的重写规则:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=1,NC,L]
RewriteRule ^.*$ index.php [NC,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多