php .htaccess 在 xampp 上不起作用(Windows 7)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24472349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:20:09  来源:igfitidea点击:

.htaccess doesn't work on xampp (windows 7)

php.htaccessxampp

提问by Jhonatan Sandoval

I'm setting my .htaccessfile right now to use friendly urls(manually). But, when i go to the url the server shows me Error 404.

我现在正在设置我的.htaccess文件以使用友好的网址(手动)。但是,当我转到 url 时,服务器向我显示Error 404

RewriteEngine on

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f  

Rewriterule ^register$ register.php 

I'm really sure that mod_rewriteis enabled because i see it when use phpinfo().

我真的很确定mod_rewrite已启用,因为我在使用时看到它phpinfo()

回答by zx81

Even though mod-rewriteis enabled, by default it is not enabled for .htaccessfiles.

即使mod-rewrite已启用,默认情况下它也不会对.htaccess文件启用。

Hold Your Breath

屏住呼吸

  • Open xampp control panel
  • Stop Apache
  • Click the Configbutton on the Apache row, and select httpd.conf
  • In that file, search for something like xampp/htdocs">
  • A bit lower, you may see a line like this: # AllowOverride All. Remove the #, which is a comment
  • Alternately, search for AllowOverride All, make sure it is in the right section, and remove the comment #
  • Save the file
  • Restart Apache, say a prayer, cross your fingers and hold your breath
  • 打开 xampp 控制面板
  • 停止阿帕奇
  • 单击ConfigApache 行上的按钮,然后选择httpd.conf
  • 在该文件中,搜索类似 xampp/htdocs">
  • 再低一点,您可能会看到这样的一行:# AllowOverride All。删除#,这是一个注释
  • 或者,搜索AllowOverride All,确保它在正确的部分,然后删除评论#
  • 保存文件
  • 重启Apache,祈祷,交叉手指并屏住呼吸

回答by rizwan

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]

if we want to remove index.php form url .First we create a .htaccess file on root directory of project with out any extension. And add this code in this file and so remove the index.php Application/config/config.php

如果我们想删除 index.php 表单 url 。首先我们在项目的根目录上创建一个 .htaccess 文件,没有任何扩展名。并在此文件中添加此代码并删除 index.php Application/config/config.php

回答by Roberto Osses Elgueta

Check in httpd.conf you tag, review this property

检查您标记的 httpd.conf,查看此属性

AllowOverride All

AllowOverride authorize use htaccess file.

AllowOverride 授权使用 htaccess 文件。

回答by LateToTheParty

This listing may be old but is still relevant so to make it a little more secure it is probably best to add a few lines.

此列表可能很旧但仍然相关,因此为了使其更安全,最好添加几行。

Deny from all
Allow from 127.0.0.1 ::1 localhost
Allow from .htaccess

Also as a side note .htaccess files slow the speed of the server so it would be best to refer to xampp documentation for best practices.

另外作为旁注,.htaccess 文件会降低服务器的速度,因此最好参考 xampp 文档以获得最佳实践。

Hope it helps.

希望能帮助到你。