如何重定向静态URL小网址 [英] How to Redirect static urls to small urls
问题描述
最近,我改变了我的网站的网址结构。但是,谷歌索引网址是给404未发现的错误。现在,我要求帮助,得到了<一href="http://stackoverflow.com/questions/5056249/how-to-redirect-rewriten-urls-to-short-urls">suggestion是这样的。
I recently changed my site url structure. But, Google indexed urls are giving 404 not found errors. Now, I asked for help and got suggestion like this.
RewriteRule ^([a-z|-]+)t(\d{3}-\d+\.html)$ /topic$2 [NC,R=301,L]
不过,对于这一点,我得到的Firefox错误:Firefox已经检测到服务器重定向此地址的方式,将永远不会完成这个请求。
But, for that, I'm getting firefox error: "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
我的previous code是这样的:
My previous code is like this:
# 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]
我需要的是这样的:重定向的URL像这样
What I need is this: redirecting urls like this.
发件人: www.mydomain.com/topic-titles-here-t273.html
From : www.mydomain.com/topic-titles-here-t273.html
要: www.mydomain.com/topic273.html
To : www.mydomain.com/topic273.html
发件人: www.mydomain.com/topic-titles-here-t273-15.html
From : www.mydomain.com/topic-titles-here-t273-15.html
要: www.mydomain.com/topic273-15.html
To : www.mydomain.com/topic273-15.html
发件人: www.mydomain.com/51-topic-titles-here-t273-15.html(注意,像职称51号)
From : www.mydomain.com/51-topic-titles-here-t273-15.html (observe, numbers like 51 in titles)
要: www.mydomain.com/topic273-15.html
To : www.mydomain.com/topic273-15.html
请指引我。
推荐答案
试试这个:
RewriteCond %{REQUEST_URI} !^/topic[0-9-]+\.html$
RewriteRule ^([a-z|-]+)t(\d{3}-\d+\.html)$ /topic$2 [NC,R=301,L]
这应该被重写排除您的新网址。
That should exclude your new URLs from being rewritten.
这篇关于如何重定向静态URL小网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!