去掉LoadModule rewrite_module modules/mod_rewrite.so前面的#
以及 AllowOverride All 就不提了。
部分博客提到 AccessFileName access.ht问题,有需要也可以看看。
不过以上都没有问题还是不行。
看了thinkPhp5 自带的htaccess文件才发现,是写错了rule。
看的视频教程上提供的规则如下:
RewriteEngine on
RewriteRule ^/test([0-9]*).html$ /test.php?id=$1
RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]结果无论如何都无效
tp5的代码如下:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>在rule一行,少了一个“/”,就只是这问题。
实际测试,只写
RewriteEngine On
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]就够了。
假如规则写成
RewriteEngine On
RewriteRule ^(.*)$ index.php?id=$1 [QSA,PT,L]那么 访问 http://localhost/文件路径/111
相当于访问
http://localhost/文件路径/index.php?id=111
本文介绍如何正确配置ThinkPHP5中的.htaccess文件来实现URL重写,包括修正缺失的“/”符号和调整RewriteRule。通过具体实例说明了如何避免常见错误,并确保重写规则正常工作。
755

被折叠的 条评论
为什么被折叠?



