apache mod_重写不工作或未启用

apache mod_重写不工作或未启用,apache,mod-rewrite,Apache,Mod Rewrite,我已经在Apache上安装了rewrite_模块并修改了php.ini 我创建了rewrite.php和.htaccess文件,但它不起作用 我的文件系统文件夹如下: /var/www/html/.htaccess内容为: /var/www/html/rewrite.php “重写”模块已加载。 允许超限设置 $cat/etc/httpd/conf/httpd.conf 选项索引跟随符号链接 不允许超限 命令允许,拒绝 通融 请再试一次 sudo a2enmod rewrite 或者使用正确的

我已经在Apache上安装了rewrite_模块并修改了
php.ini

我创建了
rewrite.php
.htaccess
文件,但它不起作用

我的文件系统文件夹如下: /var/www/html/.htaccess内容为: /var/www/html/rewrite.php “重写”模块已加载。 允许超限设置
$cat/etc/httpd/conf/httpd.conf
选项索引跟随符号链接
不允许超限
命令允许,拒绝
通融
请再试一次

sudo a2enmod rewrite
或者使用正确的apache重启命令

sudo /etc/init.d/apache2 restart 
它起作用了

我的解决办法是:

1.在/etc/httpd/conf.d/test.conf中创建一个test.conf

2.写了一些规则,比如:

<Directory "/var/www/html/test">
RewriteEngine On
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]
</Directory>

重新启动发动机
重写规则^link([^/]*).html$rewrite.php?link=$1[L]
3.重新启动Apache服务器


4.自己再试一次。

尝试设置:“AllowOverride All”

为了让mod_rewrite在Apache2.4中为我工作,我必须在下面添加“requireall-grated”行

<Directory /var/www>
   # Required if running apache > 2.4
   Require all granted

   RewriteEngine on 
   RewriteRule ^cachebust-([a-z0-9]+)\/(.*) /$2 [L] 
 </Directory>

#如果运行apache>2.4,则需要此选项
要求所有授权
重新启动发动机
重写规则^cachebust-([a-z0-9]+)\/(.*)/$2[L]
假设Apache 2.2也存在类似的要求,如果您正在使用:

<Directory /var/www>
   # Required if running apache 2.2
   Order allow,deny
   Allow from all

   RewriteEngine on 
   RewriteRule ^cachebust-([a-z0-9]+)\/(.*) /$2 [L] 
 </Directory>

#如果运行Apache2.2,则为必需
命令允许,拒绝
通融
重新启动发动机
重写规则^cachebust-([a-z0-9]+)\/(.*)/$2[L]

请注意,
errordocument404
指令有时也可以覆盖这些内容,因此,如果它不起作用,请尝试注释您的ErrorDocument指令,看看它是否起作用。上面的示例可以通过在路径中包含子文件夹来确保站点不会从缓存中获得服务,尽管文件位于服务器的根目录下。

在centOS7上,我更改了文件 /etc/httpd/conf/httpd.conf

来自AllowOverride None
允许覆盖所有

但我没有“a2enmod”命令。因为,我的apahce是[yum-install-apache],您使用哪个操作系统?(CentOS、Ubuntu等)我的操作系统是“AWSEC2 t1.micro”。抱歉,稍后很忙。很好,您找到了一个解决方案,但不要用另一个问题来完成您的回答。请注意,如果您将这些指令放入httpd.conf而不是.htaccess中,则需要目录标记。这个答案对我有效,如果我可以提出一个友好的建议,我认为最好是你在这里的答案中加入更多的链接。
$ cat /etc/httpd/conf/httpd.conf
<Directory "/var/www/html">
    Options Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny
    Allow from all
</Directory>
sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart 
<Directory "/var/www/html/test">
RewriteEngine On
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]
</Directory>
<Directory /var/www>
   # Required if running apache > 2.4
   Require all granted

   RewriteEngine on 
   RewriteRule ^cachebust-([a-z0-9]+)\/(.*) /$2 [L] 
 </Directory>
<Directory /var/www>
   # Required if running apache 2.2
   Order allow,deny
   Allow from all

   RewriteEngine on 
   RewriteRule ^cachebust-([a-z0-9]+)\/(.*) /$2 [L] 
 </Directory>