301 redirect using .htaccess

New to mod_rewrite? This is a good place to start.

301 redirect using .htaccess

Postby MetroWeb » Thu Jun 11, 2009 2:01 am

I have a new website and I would like to redirect all the old pages to my new website's new pages.

My old website is built using php. My home page is domainname.com/index.php. I do not have any problem redirecting my old website home page to my new website home page.

My problem is:

My old website pages are called into the old site by (domainname.com/index.php?p=seo friendly page name).

an example redirect would be:

redirect301 /index.php?p=breakfast http://www.domainname.com/content/category/51/74/139/

this redirect only brings up my home page of www.domainname.com however in the address bar the address displayed is http://www.domainname.com/?p=breakfast.

I need it to bring up the actual page (not the home page) at http://www.domainname.com/content/category/51/74/139/ and that address be displayed in the address bar.

I have 96 pages that are called into the old website using the (domainname.com/index.php?p= ) call in system.

The (index.php?p=) system is really giving me a problem on my redirects. Any help would be greatly appreciated.

Thanks in advance.
MetroWeb
 
Posts: 4
Joined: Thu Jun 11, 2009 1:56 am

Postby richardk » Thu Jun 11, 2009 10:43 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?p=breakfast(&.*)?$ [NC]
RewriteRule ^$ /content/category/51/74/139/? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

301 redirect using .htaccess

Postby MetroWeb » Thu Jun 11, 2009 11:33 am

richardk wrote:Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?p=breakfast(&.*)?$ [NC]
RewriteRule ^$ /content/category/51/74/139/? [R=301,L]


Hi Richard - Thanks so much for help.

I tried the code but it didn't work. I know we have to be close. The old site I want to redirect is hotspringsdining.com. I want to direct the old pages to the new pages at hotspringsrestaurantguide.com.

You will be able to see how the old site is working. The new site is built using Mambo.

Thanks in advance. I really appreciate your help as I need to get this resolved so I can move on with my new site. Thanks again.
MetroWeb
 
Posts: 4
Joined: Thu Jun 11, 2009 1:56 am

Postby richardk » Thu Jun 11, 2009 12:32 pm

What happens?
Where are you putting the mod_rewrite?
What other mod_rewrite do you have?
Are you putting the redirect mod_rewrite first? (You should.)

You may need to specify the domain name
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?p=breakfast(&.*)?$ [NC]
RewriteRule ^$ http://hotspringsrestaurantguide.com/content/category/51/74/139/? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby MetroWeb » Thu Jun 11, 2009 1:15 pm

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?p=breakfast(&.*)?$ [NC]
RewriteRule ^$ http://hotspringsrestaurantguide.com/co ... 51/74/139/? [R=301,L]

1. that is the exact and only code I have in my .htaccess file and the .htaccess file in in my public_html directory (root)

2. I then tried http://www.hotspringsdining.com/index.php?p=breakfast and that is the exact site that comes up instead of http://hotspringsrestaurantguide.com/co ... 51/74/139/.

3. I do not have any other mod_rewrite in the .htaccess file. I have only the code you show and nothing else in that file.

I know there is a solution code to make it work but I am at my witts end.

Again, I appreciate your help so very much.
MetroWeb
 
Posts: 4
Joined: Thu Jun 11, 2009 1:56 am

Postby richardk » Thu Jun 11, 2009 2:52 pm

1. that is the exact and only code I have in my .htaccess file and the .htaccess file in in my public_html directory (root)

Please explain your directory structure, i expected only one .htaccess file in your document root.

Where's the mod_rewrite for the Mambo SEF URLs?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby MetroWeb » Fri Jun 12, 2009 2:51 am

Please explain your directory structure, i expected only one .htaccess file in your document root.

Where's the mod_rewrite for the Mambo SEF URLs?[/quote]


public_html/.htaccess

There is only one .htaccess file in the document root.

I kept working with the code and finally got it to work.

Here is what worked:

Options +FollowSymLinks
RewriteEngine On
# Redirect requests for /index.php?p=sef-name to mynewdomain.com/content/category/32/51/113/
RewriteCond %{QUERY_STRING} ^p=sef-name$
RewriteRule ^index\.php$ http://mynewdomain.com/content/category/32/51/113/? [R=301,L]

I researched for about 8 hours before I was finally able to get enough information to put that code together. I am not a programmer or coder. I do web design but I can somewhat follow the logic of some programming.

I was just amazed that I couldn't search on mod_rewrite for a string /index.php?p=sef-name to a new domain name and not come up with a lot of information on how to write that.

I did find a lot of information on mod_rewrite of /index.php?p=name to /sef-name.html on a same website.

Hopefully this will get indexed in the search engines and help someone else.

Thanks for your help because your first code helped get me started in the right direction.
MetroWeb
 
Posts: 4
Joined: Thu Jun 11, 2009 1:56 am

Postby richardk » Fri Jun 12, 2009 8:47 am

The problem with the mod_rewrite i posted is it only matches requests to / not /index.php.

You should/could change
Code: Select all
^index\.php$

to
Code: Select all
^(index\.php)?$

so it matches both / and /index.php.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 110 guests

cron