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!

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.