我无法使 URL 重定向工作。我的文件似乎有问题.htaccess
。我正在使用WampServer。
以下是 .htaccess 中的代码:
重写引擎开启 RewriteRule ^contactus index.php?file=c-contactus
我无法使 URL 重定向工作。我的文件似乎有问题.htaccess
。我正在使用WampServer。
以下是 .htaccess 中的代码:
重写引擎开启 RewriteRule ^contactus index.php?file=c-contactus
RewriteRule ^/?contactus(/)?$ index.php?file=c-contactus
在 index.php?file=c-contactus 之前放一个 /
所以它变成:
/index.php?file=c-contactus
或者
RewriteRule ^contactus$ index.php?file=c-contactus
尝试:
RewriteRule ^/contactus(.*) /index.php?file=c-contactus
您必须在第一步启用 RewriteRule。
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
将 AllowOverride None 更改为 AllowOverride All
在 /etc/apache2/sites-enabled/000-deafult
RewriteEngine on
RewriteBase /your-project-folder/
RewriteRule ^contactus/?$ index.php?file=c-contactus [L,QSA]
如果您使用 localhost,请为 url rewritebase 提供根文件夹名称(您的项目在其中可用)
例如:如果你的 index.php 文件在firstproject文件夹下,那么设置如下
RewriteEngine on
RewriteBase /firstproject/
RewriteRule ^contactus/?$ index.php?file=c-contactus [L,QSA]