Jump to content

301 redirect - multiple conditions not working...


popokolok

Recommended Posts

Hello, If I put this in my .htaccess for my website only the first condition seems to function properly:

 

Options +FollowSymLinks

RewriteEngine on

 

RewriteCond %{http_host} ^DOMAIN\.com [nc]

RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,nc,L]

 

RewriteCond %{http_host} ^DOMAIN\.com/Index1.php [nc]

RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,nc,L]

 

RewriteCond %{http_host} ^www\.DOMAIN\.com/Index1.php [nc]

RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,nc,L]

 

RewriteCond %{http_host} ^DOMAIN\.com/index1.php [nc]

RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,nc,L]

 

RewriteCond %{http_host} ^www\.DOMAIN\.com/index1.php [nc]

RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,nc,L]

 

RewriteCond %{http_host} ^DOMAIN\.com/index2.php [nc]

RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,nc,L]

 

RewriteCond %{http_host} ^www\.DOMAIN\.com/index2.php [nc]

RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,nc,L]

 

What do I need to do to fix it?

 

Thanks in advance!

The host doesn't include the file path.  IE %{HTTP_HOST} will never include the /Index1.php part.  It's the host.

 

 

 

 

Also, http_host should be HTTP_HOST.

 

Alright... Thanks for the info, but still could you please then tell me how do I acomplish a 301 redirect from sub-pages to the top level domain - in other words how do I make the code seen above function properly? Thanks!!

What exactly are you trying to do?

 

Well, I have like two files that lead to the top level domain - for example: my domain.com/index.php and my domain.com/homepage.php both lead to my top-level domain.com when typed in the address, but not redirecting the surfer to the top-level domain.com... How can I use a .htaccess to redirect for example the domain.com/homepage.php to the domain.com just like redirecting the domain.com to www.domain.com using a 301 redirect?

 

Thanks!

  • 2 months later...

you dont need to indicate the next comand on the  condition as this will always look for the next line:

RewriteCond %{http_host} ^DOMAIN\.com

 

and you are indicating to look for the next comand "NC" and then indicating that it is the last

RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,nc,L]

 

it should just be:

RewriteCond %{http_host} ^DOMAIN\.com

RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,nc]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.