.htaccess 重写问题(从 CodeIgniter URL 中删除 /index.php)

发布于 2024-09-29 12:23:22 字数 1215 浏览 1 评论 0原文

我对我们网站上的一些 .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 技术交流群。

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

发布评论

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

评论(2

鯉魚旗 2024-10-06 12:23:23

我很幸运地进行了此配置:

RewriteEngine on

# 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,l]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

如果域规则匹配,则重定向(但将其作为最后一个规则)。
然后在正确的域上,如果请求不是现有文件或目录,则传递到 Code Igniter。

I had luck with this configuration:

RewriteEngine on

# 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,l]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

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.

猫烠⑼条掵仅有一顆心 2024-10-06 12:23:23

我本以为 301 重定向应该高于您的 CodeIgniter 规则,给出:

RewriteEngine on

# 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]

# CodeIgniter rules (forwards requests to index.php)
RewriteCond $1 !^(index\.php|images|robots\.txt|public)
RewriteRule ^(.*)$ /index.php/$1 [L]

我最近为网站开发了一个多站点框架,这就是我正在使用的重写顺序:首先是域,然后是直接结果通过我的 index.php。对于像 CodeIgniter 这样的现成框架,该理论应该是相同的。

I would have thought the 301 re-direct should be above your CodeIgniter rules, giving:

RewriteEngine on

# 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]

# CodeIgniter rules (forwards requests to index.php)
RewriteCond $1 !^(index\.php|images|robots\.txt|public)
RewriteRule ^(.*)$ /index.php/$1 [L]

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文