【发布时间】:2016-03-24 17:53:23
【问题描述】:
我正在尝试通过在我的 localhost 服务器上使用 .htaccess 文件来让 mod_rewrite 工作。
我的 apache2.conf 文件包含:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
还有:
Include mods-enabled/*.load
/etc/apache2/mods-enabled/rewrite.load 文件包含:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
.so 文件存在。
service apache2 restart 没有显示警告/错误
我的 .htaccess 包含:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /process.php?path=$1 [NC,L,QSA]
它位于/var/www/wp/wp-content/plugins/myplugin/
process.php 包含print_r($_SERVER);
我正在访问 http://localhost/wp/wp-content/plugins/myplugin/randomstring 并且总是收到 404 错误。
我尝试将 .htaccess 文件更改为随机字符串以尝试触发 500 错误以确保 .htaccess 正在“执行”(?),但仍然收到 404 not found 错误。
var_dump(in_array('mod_rewrite', apache_get_modules())); 返回真
我做错了什么?这始终适用于我的在线服务器。
【问题讨论】:
-
你试过'sudo a2enmod rewrite'吗?
-
检查 phpinfo() 是否启用了重写模块
-
@Nikhil 它返回:
ERROR: Module rewrite not properly enabled: /etc/apache2/mods-enabled/rewrite.load is a real file, not touching it我应该如何进行? phpinfo() 在加载的模块中显示 mod_rewrite。 -
检查这个:xmodulo.com/…
-
@Nikhil 非常感谢。我不得不编辑
/etc/apache2/sites-available/default文件并将所有AllowOverride 从none 更改为All。如果您可以将其作为答案,那么我可以接受。
标签: php wordpress apache .htaccess mod-rewrite