【问题标题】:Use .htaccess file on an apache localhost server在 apache localhost 服务器上使用 .htaccess 文件
【发布时间】:2013-01-07 13:14:34
【问题描述】:

好的,我安装了一个 Apache localhost 服务器并使用 PHP 和 MySql 运行。现在我希望能够使用.htaccess 文件以及使用RewriteRule,但我不知道该放在哪里。

我有这些目录:

C:\dev\progs Apache PHP 和 MySQL 存储在其中,每个都在它们自己的子目录中,即。 C:\dev\progs\Apache等等……

C:\dev\www 存储所有站点文件。

我需要知道将.htaccess 文件放在哪里,我需要做哪些配置,以及我的希望和梦想是否都白费了。

谢谢

【问题讨论】:

  • 我认为如果您有权访问服务器配置文件,则不应使用 .htaccess 配置,在这种情况下,您可以这样做。
  • 是的,我也听说过,只是觉得配置文件有点混乱。我还可以找到更多关于.htaccess 文件的教程。

标签: apache .htaccess configuration directory localhost


【解决方案1】:

在 localhost 的 apache 服务器上启用 .htaccess

1) Find your apache directly which uses the php installation .
2) Open your httpd.conf  with notepad, Which is located in the path \apache\conf directory
3) Find the code like below       
      #LoadModule rewrite_module modules/mod_rewrite.so
4) Remove # from above code


# AllowOverride controls what directives may be placed in .htaccess files.
 # It can be "All", "None", or any combination of the keywords:
 #   Options FileInfo AuthConfig Limit
 #
 AllowOverride All   <--- make sure this is not set to "None"


5) Save httpd.conf file
6) Restart your apache server

【讨论】:

  • 谢谢。只需添加一小部分即可避免 WAMP 用户执行第 1 步和第 2 步。单击 WAMP 图标,滚动到 Apache。您将直接获得httpd.conf 文件进行编辑。
【解决方案2】:

.htaccess 是一个配置文件,应该存储在页面所在的位置。简而言之,在你的情况下它应该是c:\dev\www,但你也应该阅读this。顺便说一句,不要忘记通过从它所在的行中删除哈希来打开 mod_rewrite

LoadModule rewrite_module modules/mod_rewrite.so

并通过更改启用 .htaccess

AllowOverride None

AllowOverride All

【讨论】:

  • 确认您已在 Apache 服务器上启用了 rewrite_module,并检查您的 httpd.conf 文件以确保没有“#”,即在此行 LoadModule rewrite_module modules/mod_rewrite 的开头注释。所以
【解决方案3】:

您将.htaccess 文件放在您希望代码控制的网络目录(以及任何子目录)中。对于重写,它通常进入根目录并作用于 index.php 页面。

例如,如果您将 .htaccess 文件放在 \dev\www\ 目录中,并且您的 .htaccess 文件有类似 RewriteRule ^(.*)$ /index.php?/$1 [L] 的内容,这是一个正则表达式,表示获取 URL 中的所有字符并附加他们到/index.php? 脚本。 /$1 是正则表达式中的反向引用。

【讨论】:

    【解决方案4】:

    试试这个。

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /projectfolder/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /projectfolder/index.php [L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2010-11-10
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 2015-11-25
      • 2012-07-09
      • 2014-07-11
      相关资源
      最近更新 更多