2

我有一个 CodeIgniter 项目放置在域的子文件夹中。对于涉及 CodeIgniter 目录的任何 url,我想让我的 .htaccess(放在 CodeIgniter 子文件夹中)执行以下操作:

  1. 从任何网址中删除“index.php”。
  2. 始终在任何 url 添加尾部斜杠。

目前我的 .htaccess 看起来像这样:


    RewriteEngine on
    RewriteBase /ci_folder/        #This is the CI Subfolder

    # Get rid of index.php
    RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

    # Add trailing slash
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*[^/])$ $1/ [L,R=301]

问题是,它只能部分工作;index.php 可以很好地删除,但是在添加尾部斜杠时,它不会重定向到“固定”url,而是重定向到本地路径 fx。

domain.com/ci_folder/method

被重定向到:

domain.com/home/sites/domain.com/public_html/ci_folder/index.php/method/

应该是:domain.com/ci_folder/method/!(也不包括任何 index.php)

- - 编辑 - -

这为我做到了:


    RewriteEngine on
    RewriteBase /ci_folder/

    RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [L]

    RewriteCond %{REQUEST_URI} !(.*)/$
    # dont rewrite if there was posted here!
    RewriteCond %{REQUEST_METHOD} !POST 
    RewriteRule ^(.*[^/])$ $1/ [L,R=301]

    RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

4

1 回答 1

3
RewriteEngine on
RewriteBase /ci_folder/

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]

RewriteCond %{REQUEST_URI} !(.*)/$
# dont rewrite if there was posted here!
RewriteCond %{REQUEST_METHOD} !POST 
RewriteRule ^(.*[^/])$ $1/ [L,R=301]

RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
于 2013-03-01T14:43:16.483 回答