htaccess with 301 redirect of index.php pages

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

htaccess with 301 redirect of index.php pages

Postby Electric Studio » Mon Oct 05, 2009 12:53 pm

Hello, thank you for looking. I have just replaced an old CMS website with a brand new WordPress solution, but am having issues with 301 redirecting the old URL's to the new, SEO friendly URL's created by WP. The old URL's where are structured like:

Code: Select all
/index.php?p=conference_programme


So when I do a 301 for that, it seems to collide with the line:

Code: Select all
RewriteRule . /index.php [L]


The last bit just seems to remove the index.php part and doesn't redirect it. The complete htaccess code is:

Code: Select all
# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Redirect 301 /index.php?p=director http://www.oxfordanimalethics.com/who-we-are/director/
Redirect 301 /index.php?p=advisers http://www.oxfordanimalethics.com/who-we-are/advisers/
Redirect 301 /index.php?p=news http://www.oxfordanimalethics.com/about-the-centre/latest-news/


Any help with this would be very appreciated. I am a complete newbie...
Electric Studio
 
Posts: 2
Joined: Mon Oct 05, 2009 12:47 pm
Location: Oxford, UK

Postby richardk » Mon Oct 05, 2009 1:14 pm

Mod_dir (Redirect) is for simple redirects only, you will need to use mod_rewrite instead.
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{QUERY_STRING} ^(.*&)?p=advisers(&.*)?$ [NC]
  RewriteRule ^(index\.php)?$ http://www.oxfordanimalethics.com/who-we-are/advisers/? [R=301,L]

  RewriteCond %{QUERY_STRING} ^(.*&)?p=director(&.*)?$ [NC]
  RewriteRule ^(index\.php)?$ http://www.oxfordanimalethics.com/who-we-are/director/? [R=301,L]

  RewriteCond %{QUERY_STRING} ^(.*&)?p=news(&.*)?$ [NC]
  RewriteRule ^(index\.php)?$ http://www.oxfordanimalethics.com/about-the-centre/latest-news/? [R=301,L]

  # BEGIN WordPress
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  # END WordPress
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Electric Studio » Mon Oct 05, 2009 9:53 pm

richardk wrote:Mod_dir (Redirect) is for simple redirects only, you will need to use mod_rewrite instead.


You are a superstar! Works a treat ;-)
Electric Studio
 
Posts: 2
Joined: Mon Oct 05, 2009 12:47 pm
Location: Oxford, UK


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 31 guests

cron