apache的URL重写

时间:2023-03-09 13:15:35
apache的URL重写

apache的url重写

第一步:修改apache\conf目录下的的httpd.conf文件

1、加载apache的url重写模块

大概122行:LoadModule rewrite_module modules/mod_rewrite.so 开启apache的url重写模块(默认是开启的)

2、让apache认识.htaccess文件

大概235行:修改    AllowOverride none 为     AllowOverride all

完了以后重启apache

第二步:在站点根目录下新建.htaccess文件,编写重写规则

大概内容如下

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule index/aa/(.*)/bb/(.*)/ test.php?aa=$1&bb=$2
</IfModule>

关于url重写的设置都很简单,核心可能是重写规则的编写,会用到正则表达式。