由于.htaccess文件

时间:2015-05-15 00:14:03

标签: php codeigniter

我很难让我的.htaccess正确无误。我使用的是codeigniter MVC。

下面是我的.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /webappl

  # Reenable after getting ssl cert
  # RewriteCond %{HTTPS} off
  # RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

  # Removes access to the system folder by users
  RewriteCond %{REQUEST_URI} ^system.*
  RewriteRule ^(.*)$ /index.php?/$1 [L]

  # When your application folder isn't in the system folder This snippet prevents user access to the application folder
  RewriteCond %{REQUEST_URI} ^application.*
  RewriteRule ^(.*)$ /index.php?/$1 [L]

  # Checks to see if the user is attempting to access a valid file, such as an image or css document, if this isn't true it sends the request to index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  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
</IfModule>

我正在使用codeigniter MVC。我在website.com/webappl下完成了mvc。并且.htcaccess文件也在website.com/webappl目录中。

$_REQUEST参数无法正常工作。在网址print_r($_REQUEST)处执行website.com/webappl/prof?parm1=value1&parm2=valu2时,它会提供输出:

Array ( [/prof] => [PHPSESSID] => 20b15a4c76eddd60ec208f422b4047b1 )

但它应该返回

Array ( [parm1] => value1, [parm2] => valu2);

我不知道哪里出错了。

1 个答案:

答案 0 :(得分:1)

试试这段代码。适用于我的应用程序。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /webappl/

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

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

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

请注意对RewriteBase / webappl /

的更改