Codeigniter重写规则

时间:2016-04-01 15:55:15

标签: php .htaccess codeigniter

我尝试将我的网址设为这样:http://domain.com/garage我尝试了这个:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteRule ^garage/?$ index.php?c=garage&m=index [NC,L]
</IfModule>
<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

我的代码出了问题,但我不明白为什么。

编辑:我将在htacces中创建所有网址。我不是用路线做什么的。

1 个答案:

答案 0 :(得分:1)

在根文件夹中创建.htaccess文件并复制以下代码

    <IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\.php|css|js|uploads|img|assets|fonts|robots\.txt|css)
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.

  ErrorDocument 404 /index.php