【发布时间】:2015-07-17 15:03:18
【问题描述】:
我已经阅读了许多类似的请求,例如:
Apache rewrite rule - prevent rewritten URL appearing in browser URL bar
但我无法弄清楚我做错了什么,任何帮助将不胜感激。
我正在使用 codeigniter 3,它的根位于以下位置:
https://example.com/api/v1.0
我已经设置了一条基本路线,并且使用 Codeigniter 一切正常,例如如果我导航到:
/api/v1.0/index.php/pages/view/about
出现适当的页面,因此所有接缝都很好。我真正想要的是重写 URL,以便在我输入时:
/api/v1.0/pages/view/about
它转到同一页面。我添加了一个重写规则的 htaccess 文件,一切都按预期工作:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /api/v1.0/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
问题是,当我输入网址时:
/api/v1.0/pages/view/about
它转到正确的页面,但浏览器 URL 更新为:
/api/v1.0/index.php/pages/view/about
我的问题是,如何阻止浏览器 URL 的更新?
更新 - 我的 Web 服务器站点位于充当 https 端点的 AWS ELB 后面。我在 httpd.conf 中有以下内容,以确保任何非“www”前缀的 URL 和任何 http 调用都被重定向到 https://www
<VirtualHost *:80>
RequestHeader set X-Forwarded-Proto "http"
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/_hostmanager/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^test\. [NC]
RewriteCond %{HTTP_HOST} !^signup\. [NC]
RewriteCond %{REQUEST_URI} !^/_hostmanager/
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
我认为此规则不会导致问题,因为它没有被调用,我提供了正确的前缀和协议。
非常感谢,
罗伯
【问题讨论】:
标签: apache .htaccess mod-rewrite