.htaccess url重写举例

时间:2022-10-28 10:51:24

.htaccess 开启url重写

<IfModule mod_rewrite.c>

RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

</IfModule>

 

url规则重写举例:

RewriteEngine On
#微信消息页
RewriteRule ^WeChat_([0-9]+)_([0-9]+).php(.*) http://z.studyems.com/WeChat/main.php/wechat/messages/kcid/$1/type/$2/

#首页
RewriteRule  ^index.php$                                    http://www.studyems.com/kaoshi/ [L]
RewriteRule  ^\/?$                                                http://www.studyems.com/kaoshi/ [L]

#搜索页
RewriteRule ^searchindex\/?$                                 http://www.studyems.com/kaoshi/searchindex\.php [L]

RewriteRule ^search_questions\/?$                             http://www.studyems.com/kaoshi/search_questions\.php [L]

#内页搜索页
RewriteRule ^search\/?$                                     http://www.studyems.com/kaoshi/search\.php [L,QSA]

#文章内页

#kaoshi-content***.html
RewriteRule ^kaoshi-content([0-9]+).html\/?$                 http://www.studyems.com/kaoshi/a$1.html [L]
RewriteRule ^kaoshi-content([0-9]+).html\/?([0-9]+)\/?$     http://www.studyems.com/kaoshi/a$1.html/$2/ [L]