htaccess 中的 URL 重写问题
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码读取为“如果这与文件、链接或目录匹配,则不执行任何操作并继续”。如果文件确实存在,则需要跳过最终的重写规则:
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: