RewriteRule and Redirect combination

Discuss practical ways rearrange URLs using mod_rewrite.

RewriteRule and Redirect combination

Postby kishor » Tue Jun 03, 2008 1:33 am

I want to use Redirect and RewriteRule at time.Here is my .htaccess file content

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect /Trangression_and_the_fall_3(reference)_2.html http://www.new.mormonbeliefs.org/trangr ... eference_2
RewriteRule ^(.*)\.html$ http://www.new.mormonbeliefs.org/$1 [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

If my Wordpress blog url like this http://www.new.mormonbeliefs.org/mormon_beliefs.html

then using above RewriteRule I can remove .html from url.

but my certain url contains following types of url
http://www.new.mormonbeliefs.org/Trangr ... (reference)_2.html

So in such case I want to use direct Redirect instead of RewriteRule.

If I remove RewriteRule it works (Redirect) but when I add RewriteRule
it's not working.

Can any one tell me any condition is required or any other way to achive this.

thanks
kishor
 
Posts: 6
Joined: Mon May 05, 2008 5:50 am

Postby richardk » Tue Jun 03, 2008 2:03 pm

You can use a RewriteRule instead of Redirect
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^Trangression_and_the_fall_3\(reference\)_2\.html$ /trangression_and_the_fall_3reference_2 [NC,R=301,L]

  RewriteRule ^(.+)\.html$ /$1 [R=301,L]

  # START 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 kishor » Tue Jun 03, 2008 9:33 pm

Thanks richard it works perfect. I found this another solution

Code: Select all
Redirect Trangression_and_the_fall_3(reference)_2.html  trangression_and_the_fall_3reference_2

RewriteCond %{REQUEST_URI} !^Trangression_and_the_fall_3\(reference\)_2\.html
RewriteRule ^(.*)\.html$ http://www.new.mormonbeliefs.org/$1 [NC,R=301,L]


But I known your solution is always perfect. thanks again
kishor
 
Posts: 6
Joined: Mon May 05, 2008 5:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 90 guests

cron