【问题标题】:Htaccess ModRewrite for CodeIgniter with a parked/redirected domain带有停放/重定向域的 CodeIgniter 的 Htaccess Mod_Rewrite
【发布时间】:2010-10-07 00:00:26
【问题描述】:

我有这种情况:

  • 主机位于 maindomain.com
  • othersite.com 停放在 maindomain.com 上
  • htaccess 用于将所有对 othersite.com 的请求重定向到子文件夹:/site-othersite/
  • 我想在 othersite.com 上使用 CodeIgniter,但在 othersite.com 中有一些目录和文件我不想让 CodeIgniter 重定向。
  • home.php 是我的 CodeIgniter 主页。

我尝试将我用于停放域的常用 ModRewrite 与我在 CodeIgniter wiki 中找到的内容结合起来,但遇到了问题。

示例: 我不希望 CodeIgniter 处理 othersite.com/demo/ 或 othersite.com/robots.txt。我有这个:

# Redirect various urls to subfolders of the format: /site-thename/

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?othersite\.com
RewriteCond %{REQUEST_URI} !^/site-othersite/
RewriteCond %{REQUEST_URI} !^/demo/
RewriteCond %{REQUEST_URI} !^robots\.txt

Rewriterule ^(.*)$ /site-othersite/home.php?/$1 [L]

CodeIgniter 安装一切正常。除了试图让 demo/ 和 robots.txt 成为 CodeIgniter 的“外部”之外是行不通的。

ModRewrite 大师们有什么建议吗?谢谢!

【问题讨论】:

  • 我想我的困惑喜欢理解 RewriteCond 行是如何工作的。是否所有这些都必须为真才能执行规则?另外,我如何格式化异常(最后两个条件)。第二个条件是防止重定向循环所必需的。

标签: mod-rewrite codeigniter


【解决方案1】:

想通了。需要分两条规则来处理:

# Redirect various urls to subfolders of the format: /site-thename/

RewriteEngine On

# Handle pages and directories that should not go through CodeIgniter.
RewriteCond %{HTTP_HOST} ^(www\.)?othersite\.com
RewriteCond %{REQUEST_URI} !^/site-othersite/
RewriteCond %{REQUEST_URI} ^/demo/ [OR]
RewriteCond %{REQUEST_URI} ^/robots.txt

Rewriterule ^(.*)$ /site-othersite/$1 [L]


# Handle CodeIgniter URLs.
RewriteCond %{HTTP_HOST} ^(www\.)?othersite\.com
RewriteCond %{REQUEST_URI} !^/site-othersite/

Rewriterule ^(.*)$ /site-othersite/home.php?/$1 [L]

【讨论】:

    猜你喜欢
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 2010-11-12
    • 2013-07-14
    • 2013-07-02
    • 1970-01-01
    • 2012-03-25
    相关资源
    最近更新 更多