首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用.htaccess更改URL (从旧url重定向到新url)

问用.htaccess更改URL (从旧url重定向到新url)
EN

Stack Overflow用户
提问于 2013-11-19 08:50:44
回答 1查看 341关注 0票数 0

我以前经常用爆炸功能来做SEO url,比如:

代码语言:javascript
复制
site.com/?/category/id/topicname/ (or site.com/index.php?/category/id/topicname/)

但是,我开始使用.htaccess。但我现在有麻烦了。老裁判员达不到这篇文章。我怎样才能改变网址:

来自:site.com/?/category/id/topicname/

致:site.com/category/id/topicname/

和

来自:site.com/index.php?/category/id/topicname/

致:site.com/category/id/topicname/

编辑:我的.htaccess文件:

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

RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

RewriteRule ^([0-9a-zA-Z-_]+)/$   index.php?modul=$1 [L,QSA]
RewriteRule ^([0-9a-zA-Z-_]+)$   index.php?modul=$1 [L,QSA]
RewriteRule ^([0-9a-zA-Z-_]+)/([0-9]+)\/?$   index.php?modul=$1&id=$2 [L,QSA]
RewriteRule ^([0-9a-zA-Z-_]+)/([0-9]+)/([0-9a-zA-Z-_]+)\/?$   index.php?modul=$1&id=$2 [L,QSA]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-19 10:03:30

将以下指令添加到您的.htaccess中,第一个条件断言以前没有重定向(否则,它将是一个无穷无尽的循环)

代码语言:javascript
复制
   RewriteCond %{ENV:REDIRECT_STATUS} !200
   RewriteCond %{QUERY_STRING} ^/(.+)$
   RewriteRule ^(index\.php)?$ /%1? [NC,R=301,L]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20066964

复制
相关文章

相似问题

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