.htaccess 重写问题(从 CodeIgniter URL 中删除 /index.php)
我对我们网站上的一些 .htaccess 规则有一个小问题 - http://www.presencemultimedia.co.uk
我们最近使用 CodeIgniter 重建了网站。为了使用漂亮的 URL,我在 .htaccess 文件中添加了一些行,如下所示:
RewriteEngine on
# CodeIgniter rules (forwards requests to index.php)
RewriteCond $1 !^(index\.php|images|robots\.txt|public)
RewriteRule ^(.*)$ /index.php/$1 [L]
# rewrites path to our primary domain (www.presencemultimedia.co.uk)
RewriteCond %{http_host} !www.presencemultimedia.co.uk$
RewriteRule ^(.*)$ http://www.presencemultimedia.co.uk/$1 [r=301,nc]
第二个重写规则旨在确保该域始终是我们的主域 (www.presencemultimedia.co.uk)。
我遇到的问题是,如果该网站是通过别名域访问的,例如 http://www.prmulti.com,URL 被重写为主域,但将 /index.php/ 添加到路径中。
例如 - http://www.prmulti.com/about/ 应重写为 http://www.presencemultimedia.co.uk/about/ 而不是 http://www.presencemultimedia.co.uk/index.php/about
任何人都可以看到我要去哪里错误的?
干杯,菲尔
I have a small issue with some .htaccess rules on our website - http://www.presencemultimedia.co.uk
We've recently re-built the website using CodeIgniter. To use nice URLs I've added some lines to our .htaccess file as below :
RewriteEngine on
# CodeIgniter rules (forwards requests to index.php)
RewriteCond $1 !^(index\.php|images|robots\.txt|public)
RewriteRule ^(.*)$ /index.php/$1 [L]
# rewrites path to our primary domain (www.presencemultimedia.co.uk)
RewriteCond %{http_host} !www.presencemultimedia.co.uk$
RewriteRule ^(.*)$ http://www.presencemultimedia.co.uk/$1 [r=301,nc]
The second rewrite rule is designed to ensure the domain is always our primary domain (www.presencemultimedia.co.uk).
The issue I have is that if the website is accessed by an aliased domain, e.g. http://www.prmulti.com, the URL is rewritten to the primary domain but adds /index.php/ to the path.
For example - http://www.prmulti.com/about/ should rewrite to http://www.presencemultimedia.co.uk/about/ instead of http://www.presencemultimedia.co.uk/index.php/about
Can anyone see where I'm going wrong?
Cheers, Phil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很幸运地进行了此配置:
如果域规则匹配,则重定向(但将其作为最后一个规则)。
然后在正确的域上,如果请求不是现有文件或目录,则传递到 Code Igniter。
I had luck with this configuration:
If the domain rule matches, redirect (but making it the last rule).
Then on the correct domain, if the request isn't an existing file or directory, pass to Code Igniter.
我本以为 301 重定向应该高于您的 CodeIgniter 规则,给出:
我最近为网站开发了一个多站点框架,这就是我正在使用的重写顺序:首先是域,然后是直接结果通过我的
index.php
。对于像 CodeIgniter 这样的现成框架,该理论应该是相同的。I would have thought the 301 re-direct should be above your CodeIgniter rules, giving:
I recently developed a multi-site framework for a website, and that's the order of re-writing I'm using: domain first, then direct the result through my
index.php
. The theory should be the same for an off-the-shelf framework like CodeIgniter.