【问题标题】:codeigniter .htaccess in shared hosting (mochahost)共享主机中的 codeigniter .htaccess (mochahost)
【发布时间】:2012-05-20 14:42:29
【问题描述】:

我想在“mydomain.com”上安装 codeigniter,托管(共享)呈现下一种结构:

  • public_html/
    • 404/
    • _private/
    • _vti_bin/
    • cgi-bin/
    • addondomain1.com/
    • addondomain2.com/
    • 代码点火器
      • 申请/
      • 系统/
    • index.php
    • .htaccess

index.php(修改):

<?php
...
  $system_path = 'codeigniter/system';
  $application_folder = 'codeigniter/application';
...

.htaccess(默认):

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

如何修改 .htaccess 以仅在 url 具有“mydomain.com”时强制/应用重写条件?

【问题讨论】:

  • 我也是.htaccess 中的菜鸟。只是因为到目前为止我还不需要更多。 ..但在您找到更好的答案之前,也许您可​​以在 addondomain 目录中粘贴一个覆盖的 .htaccess 文件。以防止它们使用(覆盖)默认 .htaccess 文件中的规则。

标签: php .htaccess codeigniter mod-rewrite shared-hosting


【解决方案1】:

要仅影响mydomain.com,请在%{HTTP_HOST} 中的第一个RewriteCond 之前添加与之匹配的RewriteCond

RewriteEngine on
# Apply rewrite only to mydomain.com
# Use [NC] for case-insensitive matching
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

如果还需要匹配www.mydomain.com,则条件为:

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.com$ [NC]

【讨论】:

    【解决方案2】:

    我在主机中为我工作的 htaccess

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 2011-12-05
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      相关资源
      最近更新 更多