[英].htaccess Is Not working in Linux(Debian) Apache2
I am using apache2 (my dummy server) which is already install with my Debian . 我正在使用apache2 (我的虚拟服务器),该服务器已经与Debian一起安装。 Every thing goes fine, but now the problem with my
.htaccess
一切都很好,但是现在我的
.htaccess
了问题
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
It's not working 没用
I think its because of apache2 version which am I using & maybe problems with my code or something I have to config on my server 我认为这是因为我正在使用的apache2版本&也许是我的代码或我必须在服务器上进行配置的问题
I want to redirect my url to main index page if its a wrong entry or unavailable 如果输入错误或不可用,我想将我的网址重定向到主索引页面
After spending a whole day, I got my answer 经过一整天,我得到了答案
In Folder 在资料夹中
apache2 >> sites-available >> There is file called default apache2 >> 可用站点 >>有一个名为default的文件
In default we have to change it 默认情况下,我们必须更改它
From: 从:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
TO: 至:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Its working. 它的工作。 It's enabled use of .htaccess files.
启用了.htaccess文件的使用。
I'd like to add that /etc/apache2/mods-available/rewrite.load
needs to be enabled: 我想补充一下
/etc/apache2/mods-available/rewrite.load
需要启用:
a2enmod rewrite
On Debian I thought it was enabled by default, but mine wasn't. 在Debian上,我认为它是默认启用的,但是我的却没有。
This code: 这段代码:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,R]
will redirect http://example.com/test.php
to http://example.com/index.php?url=test.php
if the file doesn't exist. 如果文件不存在,则会将
http://example.com/test.php
重定向到http://example.com/index.php?url=test.php
。 The only difference between my code here and your one is I have [R] instead of [QSA,L] If it still doesn't work for you and you have the htaccess file in the root folder then, I don't think it's a htaccess file problem 我的代码与您的代码之间的唯一区别是,我有[R]而不是[QSA,L]如果它仍然不适合您,并且您的htaccess文件位于根文件夹中,那么我认为它不是htaccess文件问题
Important to note that AllowOverride
only works in <Directory>
directives and will be ignored if placed inside <Location ...>
section; 需要注意的是,
AllowOverride
仅在<Directory>
指令中有效,如果放在<Location ...>
部分中,则将被忽略; this was my issue and it took me for a nice ride. 这是我的问题,我花了一个不错的时间。
Only available in sections AllowOverrideList is valid only in sections specified without regular expressions, not in , or sections.
仅在AllowOverrideList部分中可用,仅在没有正则表达式指定的部分中有效,而在或部分中则无效。
https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.