如何在服务器中设置mod_rewrite


How to setup mod_rewrite in server

我的应用程序中有这样的.htaccess文件。(仅作为安全样本)

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /app_folder/ 
   #Removes access to the system folder by users.
   #Additionally this will allow you to create a System.php controller,
   #previously this would not have been possible.
   #'system' can be replaced if you have renamed your system folder.
   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
   #Submitted by: Fabdrol
   #Rename 'application' to your applications folder name.
   RewriteCond %{REQUEST_URI} ^application.*
   RewriteRule ^(.*)$ /index.php?/$1 [L]
   #Checks to 
   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.
   # Submitted by: ElliotHaughin
   ErrorDocument 404 /index.php
</IfModule>

在(Rewritebase/app_folder/)中,如果我的应用程序在服务器中,我将在app_folder名称中放入什么?我应该把主机名放在app_folder中吗?例如

  Rewritebase /http://example.com/

因为我的app_folder现在是我的webroot。我是新上传我的HMVC代码点火器设置在服务器使用的CentOS。

在Ubuntu(linux)中:

磨合终端:

a2enmod rewrite

然后:

service apache2 restart

mod_rewrite现在将启用!


在Windows中(wamp)

您可以手动编辑httpd.conf文件

left click wampmanager -> Apache -> httpd.conf

这将在记事本中打开该文件,您可以找到该行#LoadModule rewrite_module modules/mod_rewrite.so并删除注释符号"#"以激活模块。然后保存文件并重新启动Apache以激活此更改。