Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

redirect - Can I use .htaccess rules using wildcard for site, followed by rewrites for specific pages?

I am trying to permanently redirect an entire site, where approx. 130 links remain the same except for the new domain, and then approx. 20 links have to be redirected by file name. I cannot get code to do both.

I have this beginning on the first line of my htaccess page:

RewriteEngine on
RewriteRule ^resources$ http://www.thelastdancer.com/blog? [R=301,L]
RewriteRule ^(.*)$ https://thelastdancer.com/$1 [R=301,L]

I can get the second rule to work - all my articles redirect perfectly when the /pagetitle matches. I cannot get the singe pages to redirect: https://balletforadults.com/resources SHOULD OPEN TO https://thelastdancer.com/blog I have also tried putting the first rule in the second position, no luck.

Thanks for any guidance - I have been searching through mountains of redirect code, and can't get anything to work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Could you please try following Rules, written based on your shown samples. We need to use RewriteCond here to check from which domain(host) name request is coming from and then accordingly redirecting request from bal.... to thelasdancer domain.

RewriteEngine ON
RewriteCond  %{HTTP_HOST} balletforadults.com [NC]
RewriteRule ^resources/?$ http://thelastdancer.com/blog [R=301,L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...