繁体   English   中英

301从子文件夹中的动态URL重定向到新的静态URL

[英]301 redirect from dynamic URL in subfolder to a new static URL

我查看了所有用于将动态URL重定向到静态URL的不同解决方案,但是找不到与我的问题相关的任何案例。

我想知道什么是.htaccess的正确301重定向规则

附加信息:

  • 启动新网站后,旧的URL被删除。
  • 旧网址位于子文件夹(/ desarrollo / mantenedores /)中
  • “ art_id”是字符串,“ 61”是文章

在这种情况下,我想将OLD动态URL重定向到其单独的静态URL。

旧网址= http://example.com/desarrollo/mantenedores/art_indice.asp?art_id=61

新网址= http://example.com/comunidad/articles/2/tipos-de-sociedades

谢谢...

请尝试填充一个rewritemap文件(请参见此处 )以与URL目标相对应。

创建一个映射文件,在其中放置所需的所有类别:

RewriteMap mapoldtonew \
  dbm:/web/htdocs/yoursite/rewriterules/mapoldtonew.map

关于示例,您的地图文件可能包含以下内容:

art_id=61        articles/2/tipos-de-sociedades
...

然后在这里进行困难的部分:

RewriteCond %{REQUEST_URI} desarrollo/(.*)
RewriteCond %{QUERY_STRING} (([^=]+)=([0-9]+))
# The following rule doesn't touch the URL, but 
# will try to search into the map file and
# create an OLDTONEW environment variable with the string found
# and if not found, assign OLDTONEW to "notfound"
RewriteRule . - [QSA,E=OLDTONEW:${mapoldtonew:%1|notfound}]

# if the OLDTONEW is not empty and is not found:
RewriteCond %{ENV:OLDTONEW} notfound
# this should never happen => 404:
RewriteRule . - [R=404,L]

# Reach here means :
# - OLDTONEW is empty
# - OLDTONEW is was found
# => if OLDTONEW is not empty:
RewriteCond %{ENV:OLDTONEW} !^$
# make the redirection to the corresponding found:
RewriteRule . /%{ENV:CATEGORYREVERSE} [QSA,L]

这应该工作。 如果不尝试在第一个 RewriteRule指令中将%1更改为%2 如果还是不能,您可能有足够的线索来完成工作。 如果您没有足够的线索...

两个提示:


请尝试使用RewriteLog指令:它可以帮助您RewriteLog此类问题:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

我最喜欢的用于检查正则表达式的工具:

http://www.quanetic.com/Regex (请不要忘记选择ereg(POSIX)而不是preg(PCRE)!)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM