Jump to content
JASPER

Mod_rewrite help required for 301 re directs

Recommended Posts

I have found how to ftp transfer a .htaccess without the website crashing! I am using FileZiller which shows all the files unlike FTP Surfer which I think is a bit outdated now.!

I have tried this mod-rewrite inside a .htaccess file in my root:
RewriteEngine On
RewriteRule ^brand_new_home_warranty.htm$ /nhbc-new-home-warranty.htm

and it works a treat.

But how do I add further re directs such as?
RewriteEngine On
RewriteRule ^brand_new_home_warranty.htm$ /nhbc-new-home-warranty.htm
RewriteRule ^new_home_warranty.htm$ /nhbc-home-warranty.htm
as an example?

I would also like to know how to re dircet something in a folder like:
Old URL:
www.brand-newhomes.co.uk/homes/adverts/index.php to
New URL:
www.brand-newhomes.co.uk/homes/index.php
I think it may be more to do with where the .htaccess file for this is put rather than the code.
 
I would also like to know what the mod_rewrite code would be fior an error 404 re dierct to a custom error page.

I do hope someone will be able to help me and any help would be much appreciated.

Share this post


Link to post
Share on other sites

On my Apache server here is how I do a 301 permanent redirect for a page:
 
 

RewriteEngine on
 
Redirect permanent /oldpagename.htm http:// www. domainname.com /newpagename.htm

 
RewriteEngine on is at the very top of the file, above my permanent redirects for the different versions of the domain name.
 
My friend does it another way but gets the same results:
 

redirect 301 /old-file-name.htm http:// www. domainname.com/new-file-name.htm


NOTE: take out the spaces! I had to put them in so you could see the whole code

Edited by WiseWebmaster

Share this post


Link to post
Share on other sites
But how do I add further re directs such as?

RewriteEngine On

RewriteRule ^brand_new_home_warranty.htm$ /nhbc-new-home-warranty.htm

RewriteRule ^new_home_warranty.htm$ /nhbc-home-warranty.htm as an example?

 

Keep on adding the RewriteRule with the old page to the new. Every line represents a new redirect. You only need to write "RewriteEngine On" once in the file.

 

 

 

I would also like to know how to re dircet something in a folder like:

Old URL:

www.brand-newhomes.co.uk/homes/adverts/index.php to

New URL:

www.brand-newhomes.co.uk/homes/index.php

 

RewriteRule ^homes/adverts/index.php$ /homes/index.php

Share this post


Link to post
Share on other sites

 Yes it is redirecting but the headers are not looking right.

php_network_getaddresses: getaddrinfo failed: Name or service not known (0)

 

Should look something like this:

HTTP/1.1 301 Moved Permanently =>
Date => Fri, 01 Feb 2013 15:14:01 GMT
Server => Apache
Location => http://www.brand-newhomes.co.uk/

Content-Length => 237
Connection => close
Content-Type => text/html; charset=iso-8859-1


 

Share this post


Link to post
Share on other sites

I have no idea what to do about this.

Does it matter as far as google is concerned and duplicate content?

At least it is redirecting now.

Share this post


Link to post
Share on other sites

Thanks Fabio, it all seems quite complicated.

If I was starting out today instead of six years ago, I would neverhave learned  this lot now.

Share this post


Link to post
Share on other sites

I need one last bit of help.

Where do I put this mod_rewrite re direct?

 

Old URL:
www.brand-newhomes.co.uk/homes/adverts/index.php to
New URL:
www.brand-newhomes.co.uk/homes/index.php

 

RewriteRule ^homes/adverts/index.php$ /homes/index.php

 

Say I have folders  website

                                           > htdocs

                                               .htaccess here? > homes

                                                                    or  .htaccess here?   > adverts

 

The "advert" folder is being deleted and the contents put in the "homes" folder.

Does the .htaccess go in "homes"  or in "htdocs"?

I have tried both and neither seem to work.


 

Share this post


Link to post
Share on other sites

Nope dont work there.

 

I added: 

RewriteRule ^forum/smf//buying-a-new-home.htm$ /buying-a-new-home.htm

 

to the .htaccess that all the other 301's  work in and it did not re direct.

I did wonder if it should be in either the forum or SMF sub directories (folders)  ie under the root dircctory.

 

As you can see I would like to do the re directs to reduce the errors as mentioned ion my other post.

Share this post


Link to post
Share on other sites

The link is written with two //.

Need to find a way to change the link on my forum page menu tabs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×