Solved

,htaccess 301 redirect

Posted on 2016-10-03
10
47 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

786 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