JayKay Posted August 23, 2010 Share Posted August 23, 2010 1) I have a redirect from mypage.com to www.mypage.com/main/about-us/ in htaccess with Quote RewriteCond %{HTTP_HOST} ^mypage.com [NC] RewriteRule ^(.*)$ http://www.mypage.com/main/about-us/$1 [L,R=301] How can I redirect both from www.mypage.com and mypage.com =to=> www.mypage.com/main/about-us??? If the www.mypage.com is the same with www.mypage.com/main/about-us because it is redirected, will that affect SEO somehow? 2) with the help of htaccess I receive the variable from the URL ie. www.mypage.com/variable/ and in my index.php script there is a condition that if this variable is not one of the 4 values and is incorrect then Quote header("HTTP/1.0 404 Not Found"); exit(); but all I see is blank screen when I type www.mypage.com/asdfa/ But I checked with Server header checker tool http://www.webrankinfo.com/english/tools/server-header.php and it showed that the server gave 404 error correctly but as I said the screen is blank BUT when i type www.mypage.com/sdfsdf then I see the correct 404 error response. why is that so? should I be concerned? my htaccess: Quote Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule .* - [L] RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ index.php?lang=$1&page=$2&t=$3 [L] RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?lang=$1&page=$2&t=$3 [L] RewriteRule ^([^/]*)/([^/]*)/$ /index.php?lang=$1&page=$2 [L] RewriteRule ^([^/]*)/([^/]*)$ index.php?lang=$1&page=$2 [L] Quote Link to comment https://forums.phpfreaks.com/topic/211535-redirect-and-404/ Share on other sites More sharing options...
cags Posted August 24, 2010 Share Posted August 24, 2010 1) It's not entirely clear what you mean here. The combination you have there will redirect any page request to the mypage.com domain to the URL specified (i.e. http://www.mypage.com/main/about-us/%{REQUEST_URI}), is that really what you wish to do? Either way, if you want to also match requests to the www. domain then you can use... RewriteCond %{HTTP_HOST} ^(www\.)?mypage.com [NC] But bare in mind this will cause a redirect loop. If for example you requested http://www.mypage.com/foo, Apache would do a 301 redirect to http://www.mypage.com/main/about-us/foo. Since the %{REQUEST_URI} will also match the .* pattern you are using this will then get redirected to http://www.mypage.com/main/about-us/main/about-us/foo and so forth, continually adding in main/about-us/ until the server hits it's redirect limit and throws a 500 server error. 2) There is no reason why that should display anything other than a blank page as you are not echo'ing out anything, you are simply sending a 404 response code to the client. This is not the same as Apache triggering a 404 error and redirecting to a 404 error page. The header you are using is what should be used for creating custom 404 events. If variable can only be 1 of 4 values you would be better off checking this before PHP is invoked, using something like... RewriteCond %{REQUEST_URI} ^(var1|var2|var3|var4) // whatever rewrite rule This way you will only be rewriting the valid URLs and all other URLs will throw the 404 error. Quote Link to comment https://forums.phpfreaks.com/topic/211535-redirect-and-404/#findComment-1103058 Share on other sites More sharing options...
JayKay Posted August 24, 2010 Author Share Posted August 24, 2010 Thanks for your answer. The second clear to me but about the first. I would like that if I type www.mypage.com or mypage.com then I get redirected to www.mypage.com/main/about-us/ could you please help me? with this rule that I have only mypage.com gets redirected to www.mypage.com/main/about-us/ but when I type www.mypage.com then I get www.mypage.com is that a good practice regarding SEO if www.mypage.com is the same as www.mypage.com/main/about-us/? Quote Link to comment https://forums.phpfreaks.com/topic/211535-redirect-and-404/#findComment-1103339 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.