[英]301 redirect from dynamic URL in subfolder to a new static URL
我查看了所有用於將動態URL重定向到靜態URL的不同解決方案,但是找不到與我的問題相關的任何案例。
我想知道什么是.htaccess的正確301重定向規則
附加信息:
在這種情況下,我想將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.