slj90 Posted May 23, 2014 Share Posted May 23, 2014 header('Location: www.website.com/username'); goes to www.website.com/actions/username how can I make it just go to www.website.com/username Thanks Quote Link to comment https://forums.phpfreaks.com/topic/288705-header-loaction-to-different-directory/ Share on other sites More sharing options...
IanA Posted May 23, 2014 Share Posted May 23, 2014 That should work? Is there a redirect on the url you're trying to go to, or is there something in the .htaccess file which is automatically putting 'actions' into the url? Quote Link to comment https://forums.phpfreaks.com/topic/288705-header-loaction-to-different-directory/#findComment-1480572 Share on other sites More sharing options...
slj90 Posted May 24, 2014 Author Share Posted May 24, 2014 Hi, There is nothing in the .htaccess that goes to 'actions' RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1 However, the page that the script is on is within the /actions directory. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/288705-header-loaction-to-different-directory/#findComment-1480672 Share on other sites More sharing options...
Solution Frank_b Posted May 24, 2014 Solution Share Posted May 24, 2014 I think using the full URL with 'http://' should solve your problem: header('Location: http://www.website.com/username'); Quote Link to comment https://forums.phpfreaks.com/topic/288705-header-loaction-to-different-directory/#findComment-1480691 Share on other sites More sharing options...
Jacques1 Posted May 24, 2014 Share Posted May 24, 2014 In addition to what Frank already said: header('Location: www.website.com/username'); goes to www.website.com/actions/username It doesn't. The URL points to a subdirectory in the current path. The www.website.com part is not interpreted as a domain. Unfortunately, modern browsers hide all the technical details and accept pretty much any input into the URL bar, so people start to forget how an URL actually looks like. An absolute Internet URL consists of a scheme, a host and a path: https://example.com/foo/bar If you leave out the scheme, you get a relative URL which only consists of a path. So just writing down www.google.com does not get you to Google. It's interpreted as a (relative) path on your own site, which is probably not what you want. So, yes, the “https://” or “http://” is significant. However, you can leave out the scheme if you want to use the current one: //example.com/foo/bar For an HTTPS URL, this would point to https://example.com/foo/bar, for an HTTP URL, it would point to http://example.com/foo/bar. Quote Link to comment https://forums.phpfreaks.com/topic/288705-header-loaction-to-different-directory/#findComment-1480698 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.