popokolok Posted November 17, 2008 Share Posted November 17, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/133125-301-redirect-multiple-conditions-not-working/ Share on other sites More sharing options...
corbin Posted November 17, 2008 Share Posted November 17, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133125-301-redirect-multiple-conditions-not-working/#findComment-692351 Share on other sites More sharing options...
popokolok Posted November 18, 2008 Author Share Posted November 18, 2008 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!! Quote Link to comment https://forums.phpfreaks.com/topic/133125-301-redirect-multiple-conditions-not-working/#findComment-692823 Share on other sites More sharing options...
popokolok Posted November 19, 2008 Author Share Posted November 19, 2008 Anybody anything? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/133125-301-redirect-multiple-conditions-not-working/#findComment-693644 Share on other sites More sharing options...
corbin Posted November 20, 2008 Share Posted November 20, 2008 What exactly are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/133125-301-redirect-multiple-conditions-not-working/#findComment-694064 Share on other sites More sharing options...
popokolok Posted November 20, 2008 Author Share Posted November 20, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/133125-301-redirect-multiple-conditions-not-working/#findComment-694612 Share on other sites More sharing options...
edw Posted February 4, 2009 Share Posted February 4, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/133125-301-redirect-multiple-conditions-not-working/#findComment-754373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.