重写以下3个URL
example/index.php?page=search 到 example/search
example/index.php?page=profile&value=我的名字 到 http:// example。 com / myname
example/index.php?page=stats&type=daily 到 example/stats/daily
当前.htaccess的写法如下:
Current .htaccess is written as the following:
Options -MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+)&value=([^\s&]+) [NC] RewriteRule ^ index/%1/%2? [R=302,L,NE] RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+)&type=([^\s&]+) [NC] RewriteRule ^ index/%1/%2? [R=302,L,NE] RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC] RewriteRule ^ index/%1/? [R=302,L,NE] RewriteRule ^index/([^/]+)/([^/]+)/?$ /index.php?page=$1&value=$2 [NC,L,QSA] RewriteRule ^index/([^/]+)/([^/]+)/?$ /index.php?page=$1&type=$2 [NC,L,QSA] RewriteRule ^index/([^/]+)/?$ /index.php?page=$1 [NC,L,QSA]我需要从第一个和第三个URL中删除/ index /,从第二个URL中删除/ index / profile/。
I need to remove /index/ from the first and third URL, and /index/profile/ from the second one.
所有评论&欢迎提出建议。
All comments & suggestions are welcomed.
推荐答案搜索和配置文件不能同时使用相同的正则表达式模式。例如,如果有人请求:
You can't have both the search and profile be the same regex pattern. For example, if someone requests:
example/index/foo他们是要转到名为 foo的页面还是转到名为 foo的用户的个人资料?您需要添加将两者分开的内容,例如:
Are they trying to go to a page called "foo" or go to a profile of a user named "foo"? You need to add something that separates the two, maybe something like:
Options -MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} /index\.php\?page=profile&value=([^\s&]+) [NC] RewriteRule ^ profile/%1? [R=302,L,NE] RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+)&type=([^\s&]+) [NC] RewriteRule ^ page/%1/%2? [R=302,L,NE] RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+)(\ |$) [NC] RewriteRule ^ page/%1? [R=302,L,NE] RewriteRule ^profile/([^/]+)/?$ /index.php?page=profile&value=$1 [NC,L,QSA] RewriteRule ^page/([^/]+)/([^/]+)/?$ /index.php?page=$1&type=$2 [NC,L,QSA] RewriteRule ^page/([^/]+)/?$ /index.php?page=$1 [NC,L,QSA]这会使您的网址看起来像:
This makes your urls look like:
example/profile/myname example/page/search example/page/stats/daily更多推荐
.htaccess多个参数的重写规则
发布评论