【问题标题】:How to setup mod_rewrite in server如何在服务器中设置 mod_rewrite
【发布时间】:2015-03-30 01:38:37
【问题描述】:

我的应用中有这样的 .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。我是使用 CentOS 在服务器中上传我的 HMVC codeigniter 设置的新手。

【问题讨论】:

    标签: php codeigniter mod-rewrite codeigniter-hmvc


    【解决方案1】:

    在 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 以激活此更改。

    【讨论】:

    • 我应该删除 app_folder 名称,然后像这样 RewriteBase / 离开 /(斜线)/
    • 如果在根目录下,只需斜线。如果在服务器根目录中的某个文件夹中,则为/foldername/。所以,我想说,在你的情况下 - 只需斜线 /
    • 谢谢老兄你救了我的工作状态哈哈! :)
    猜你喜欢
    • 2012-11-28
    • 2016-01-16
    • 2022-01-21
    • 2010-10-24
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    相关资源
    最近更新 更多