我试图通过在我的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正在执行&#34;(?),但仍然收到404未找到错误。< / p>
var_dump(in_array('mod_rewrite', apache_get_modules()));
返回true
答案 0 :(得分:3)
使用php_info()检查模块是否已启用。如果有一些错误。
尝试以下命令。
sudo a2enmod rewrite
我认为如果您将(/ etc / apache2 / sites-available / default)AllowOverride none
更改为AllowOverride All
,那么它将会有效。
如果您仍然收到错误,请执行here提及的步骤。
该教程有点旧,但您可以使模块正常工作。
我希望这会有所帮助。