且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自定义URL或隐藏查询字符串使用的.htaccess

更新时间:2023-02-23 08:40:50

这个规则应该工作:

  RewriteEngine叙述上
的RewriteBase / cashearn /

的RewriteCond%{} THE_REQUEST /index\.php\?page=([^\s&]+)[NC]
重写规则^指数/页/ 1%? [R = 302,L]

的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^指数/页/([^ /] +)/ $的index.php?网页= $ 1 [L,QSA,NC]
 

这会让你有网址为 http://domain.com/index/page/mobile 您的网页上。

I am new one, I learn .htaccess. I want to customize my URL from index.php?page=mobile to index/page/mobile

I used this code but it doesn't work:

RewriteEngine on
RewriteRule    ^index/([0-9]+)/?$    index.php?page=$1    [NC,L]    # Handle product requests

and

RewriteEngine on
RewriteRule ^index/([^/.]+)/?$ index.php?page=$1 [L]

This rule should work:

RewriteEngine on
RewriteBase /cashearn/

RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ index/page/%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index/page/([^/]+)/?$ index.php?page=$1 [L,QSA,NC]

This will let you have URL as http://domain.com/index/page/mobile on your page.