htaccess 中的 URL 重写问题

发布于 2024-08-31 03:42:52 字数 1295 浏览 1 评论 0原文

我对 htaccess 重定向的世界相当陌生。我试图将我的 Zend MVC 中的所有重定向强制到我的 https,但是对于不通过索引控制器的请求,我收到 请求的 URL 未找到错误

示例

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

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

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

正常工作。 URL

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>

我需要调整哪些内容才能使 URL

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

正常工作?

Am rather new to this world of htaccess redirects.Am trying to force all redirects in my Zend MVC to my https but I get a requested URL not found error on requests that dont go though the index controller

Example

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

gives a requested URL /auth/register not found error. However if I remove the https redirect rule it works fine over http. If I adjust the URL to

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

it works fine.
The URL

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

works just fine since it goes through the index controller.

My .htaccess file looks like this

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>

What do I need to adjust to get the URL

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

working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神回复 2024-09-07 03:42:52

您的代码读取为“如果这与文件、链接或目录匹配,则不执行任何操作并继续”。如果文件确实存在,则需要跳过最终的重写规则:

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

Your code reads as "If this matches a file, link, or directory, then do nothing and continue." You need to skip the final rewrite rule in the case the file actually exists:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=1,NC,L]
RewriteRule ^.*$ index.php [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文