首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用QUERY_STRING重写url

用QUERY_STRING重写url
EN

Stack Overflow用户
提问于 2019-05-03 18:12:39
回答 1查看 34关注 0票数 0

我想把http://example.com/test/index.php?id=123重写为http://example.com/test/item/123/http://example.com/test/index.php?id=123重定向到人类友好的url。

我不知道我的htaccess有什么问题:

代码语言:javascript
复制
Options +FollowSymLinks -MultiViews

RewriteEngine On    
RewriteBase /test/

RewriteCond %{QUERY_STRING} ^id=([a-z0-9]+)$ [NC]
RewriteRule ^/item/%1/? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^item/([a-z0-9]+)/$ index.php?id=$1 [L]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-03 18:24:11

您可以在您的RewriteRule文件中使用以下/test/.htaccess

代码语言:javascript
复制
Options +FollowSymLinks -MultiViews
RewriteEngine on

#redirect old url to the new one
RewriteCond %{THE_REQUEST} /test/index\.php\?id=([^\s]+) [NC]
RewriteRule ^ /test/item/%1? [L,R=301]
#internally map new url to the old one
RewriteRule ^item/(.+)/?$ /test/index.php?id=$1 [L,NC]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55975156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档