Solved

,htaccess 301 redirect

Posted on 2016-10-03
10
37 Views
Last Modified: 2016-10-31
Hello,

What will be 301 redirect code in .htaccess for:

abc.com/html/xyz/oxo.html   To >   abc.com/asd/qwe/luv/

Thanks.
0
Comment
Question by:tahirr
  • 5
  • 4
10 Comments
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 500 total points (awarded by participants)
ID: 41827391
Assuming that the path is fixed, try this:
RewriteEngine On
RewriteRule ^html/xyz/oxo\.html$ /asd/qwe/luv/ [R=301,NC,L]

Open in new window


If parts of the URL are variable, you'll need to indicate which ones.
0
 

Author Comment

by:tahirr
ID: 41827404
Thanks Terry for a super fast reply. Moved the hosting few hours ago and propagation should be done soon then I will try your suggestion and let you know.

Thanks.
0
 

Author Comment

by:tahirr
ID: 41828248
Good Morning,

I have tried this code now and it does not redirect :(
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points (awarded by participants)
ID: 41828705
Ok, there's a process to go through when it's not working as expected.

The first parameter to RewriteRule is a pattern for matching the URL. We can relax the pattern until we do get a match, and then tighten it up again once we understand why.

I find when I'm testing these rules in Chrome it tends to cache or remember redirects that have previously been applied. What seems to help is to open a new Incognito/Private window each time I test a pattern. Once the page has redirected, I close all Incognito tabs/windows and open a new one to do a fresh test. You might like to try this technique too.

Firstly, try this:

RewriteEngine On
RewriteRule (.*)/oxo\.html$ /asd/qwe/luv/?from=$1 [R=302,NC,L]

Open in new window


The .* part of the pattern matches anything, so provided you try to access anything ending with /oxo.html it should redirect. If not, then it's not the RewriteRule that's going wrong.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 35

Expert Comment

by:Terry Woods
ID: 41828706
Note that you should test this kind of thing on a development server before putting it live.
0
 

Author Comment

by:tahirr
ID: 41829049
Thanks for your time and detailed explanation. I will try your suggestions tonight and let  you know how it went.

One confusion if you could clear will me it even easier for me. If we redirect the old page by placing html 301 redirect code in header. Will it still transfer the SEO juice to new page or will it effect it? Do you think 301 redirect works the same in either .htaccess or css redirect or html redirect?

Thanks.
tahir.
0
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 500 total points (awarded by participants)
ID: 41829054
If you're talking about using an HTML header refresh, then in my understanding that isn't a 301 redirect, so no it won't transfer the SEO. You need to use the .htaccess.

For a live page, you should always test with a R=302 (temporary redirect) until you're sure you've got it right, otherwise you can permanently send traffic to the wrong place. 301 = permanent.
0
 

Author Comment

by:tahirr
ID: 41829063
Thanks
0
 

Author Comment

by:tahirr
ID: 41867735
I am sorry for not posting my results. Human nature, we come back to check on status when need help and get lazy once problem is solved. : (

I was not able to use your code, for some reason it was not working. My site had gone live for two days at the point and I was in panic mode to loose SEO juice and did not want to risk that by waiting for further solution. I found a plugin for wordpress and it did solve my issue.

I am sure the information in this post will help someone in the future. It could be me making some mistake trying to implement it.

Thanks for your help. Kudos. : )
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now