【问题标题】:How to Redirect static urls to small urls如何将静态网址重定向到小网址
【发布时间】:2011-02-21 16:35:38
【问题描述】:

我最近更改了我的网站网址结构。但是,谷歌索引的 url 给出了 404 not found 错误。现在,我寻求帮助并得到了这样的suggestion

  RewriteRule ^([a-z|-]+)t(\d{3}-\d+\.html)$ /topic$2 [NC,R=301,L]

但是,为此,我收到了 firefox 错误:“Firefox 检测到服务器正在以永远不会完成的方式重定向对该地址的请求。”

我之前的代码是这样的:

# FORUMS PAGES
###############
# FORUM INDEX REWRITERULE WOULD STAND HERE IF USED. "forum" REQUIRES TO BE SET AS FORUM INDEX
# RewriteRule ^forum\.html$ /index.php [QSA,L,NC]
# FORUM RewriteRule ^[a-z0-9_-]*-f([0-9]+)/?(page([0-9]+)\.html)?$ /viewforum.php?f=$1&start=$3 [QSA,L,NC]
# TOPIC WITH VIRTUAL FOLDER RewriteRule ^[a-z0-9_-]*-f([0-9]+)/topic([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?f=$1&t=$2&start=$4 [QSA,L,NC]
# GLOBAL ANNOUNCES WITH VIRTUAL FOLDER RewriteRule ^announces/topic([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?t=$1&start=$3 [QSA,L,NC]
# TOPIC WITHOUT FORUM ID & DELIM RewriteRule ^([a-z0-9_-]*)/?topic([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?forum_uri=$1&t=$2&start=$4 [QSA,L,NC]
# PROFILES ADVANCED RewriteRule ^[a-z0-9_-]*-u([0-9]+)\.html$ /memberlist.php?mode=viewprofile&u=$1 [QSA,L,NC]
# USER MESSAGES ADVANCED RewriteRule ^[a-z0-9_-]*-u([0-9]+)-(topics|posts)(-([0-9]+))?\.html$ /search.php?author_id=$1&sr=$2&start=$4 [QSA,L,NC]
# GROUPS ADVANCED RewriteRule ^[a-z0-9_-]*-g([0-9]+)(-([0-9]+))?\.html$ /memberlist.php?mode=group&g=$1&start=$3 [QSA,L,NC]
# POST RewriteRule ^post([0-9]+)\.html$ /viewtopic.php?p=$1 [QSA,L,NC]
# ACTIVE TOPICS RewriteRule ^active-topics(-([0-9]+))?\.html$ /search.php?search_id=active_topics&start=$2&sr=topics [QSA,L,NC]
# UNANSWERED TOPICS RewriteRule ^unanswered(-([0-9]+))?\.html$ /search.php?search_id=unanswered&start=$2&sr=topics [QSA,L,NC]
# NEW POSTS RewriteRule ^newposts(-([0-9]+))?\.html$ /search.php?search_id=newposts&start=$2&sr=topics [QSA,L,NC]
# THE TEAM RewriteRule ^the-team\.html$ /memberlist.php?mode=leaders [QSA,L,NC]

#####################################################

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([a-z0-9_-]+)/?(page([0-9]+)\.html)?$ /viewforum.php?forum_uri=$1&start=$3 [QSA,L,NC]

我需要的是:像这样重定向网址。

来自: www.mydomain.com/topic-titles-here-t273.html

收件人: www.mydomain.com/topic273.html

来自: www.mydomain.com/topic-titles-here-t273-15.html

收件人: www.mydomain.com/topic273-15.html

来自: www.mydomain.com/51-topic-titles-here-t273-15.html(注意,标题中的数字类似于 51)

收件人: www.mydomain.com/topic273-15.html

请指导我。

【问题讨论】:

  • 无限重定向的情况。重定向的其他规则是什么?您可以检查您的访问日志,一次又一次地重定向到哪个地址,并使用该信息更新问题。

标签: .htaccess mod-rewrite http-status-code-404


【解决方案1】:

试试这个:

RewriteCond %{REQUEST_URI} !^/topic[0-9-]+\.html$
RewriteRule ^([a-z|-]+)t(\d{3}-\d+\.html)$ /topic$2 [NC,R=301,L]

这应该排除您的新网址被重写。

【讨论】:

  • 哦,添加条件,谢谢。
猜你喜欢
  • 1970-01-01
  • 2016-09-01
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 2011-02-09
  • 2020-09-29
相关资源
最近更新 更多