Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

,htaccess 301 redirect

Posted on 2016-10-03
10
48 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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
 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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.

828 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