driz Posted December 16, 2009 Share Posted December 16, 2009 Hi, I want to make a login.php file look like /account/ and also make all requests to that file become that url as well, so say a person types login.php?logout=true it will become /account?logout=trueFrom what I understand it will require both a mod_rewrite of the url and also a redirect for when a person access the query Link to comment Share on other sites More sharing options...
Synook Posted December 17, 2009 Share Posted December 17, 2009 You don't have to redirect, you can use RewriteCond to capture the querystring.Something like: RewriteCond %{QUERY_STRING} (.*)RewriteRule ^account/$ login.php?%1 Link to comment Share on other sites More sharing options...
driz Posted December 17, 2009 Author Share Posted December 17, 2009 Tried that but it doesn't work. Just to clarify what I want to happen:If I type this: http://domain.com/login.php or http://domain.com/login.php?loggedout=true or if a script links to that file etc then the URL will be auto rewritten as http://domain.com/account/ or http://domain.com/account/?loggedout=trueThe code provided still allowed me to access login.php as domain.com/login.php and showed 404 when looking at /account/Thanks Link to comment Share on other sites More sharing options...
driz Posted December 17, 2009 Author Share Posted December 17, 2009 Any updates on this? Thanks Link to comment Share on other sites More sharing options...
Synook Posted December 17, 2009 Share Posted December 17, 2009 I'll fiddle with it when I have access to my test server. Note you will still be able to access the target page using its original address unless you further rewrite or deny it. Link to comment Share on other sites More sharing options...
driz Posted December 17, 2009 Author Share Posted December 17, 2009 I'll fiddle with it when I have access to my test server. Note you will still be able to access the target page using its original address unless you further rewrite or deny it.If you can still access the file and the system is directing to that file then the current rewrite isn't much good. I need it to change it to the new URL. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 17, 2009 Share Posted December 17, 2009 URL rewriting doesn't change the URL the user types in, it just instructs the server to direct various URLs which otherwise don't exist to other resources for handling. Link to comment Share on other sites More sharing options...
driz Posted December 17, 2009 Author Share Posted December 17, 2009 URL rewriting doesn't change the URL the user types in, it just instructs the server to direct various URLs which otherwise don't exist to other resources for handling.That's what I meant. I need the file to remain as login.php but I don't want to be accessible. If someone either types it in or a script links to it then the URL is automatically changed to /account/ Link to comment Share on other sites More sharing options...
Synook Posted December 18, 2009 Share Posted December 18, 2009 Ooh, I thought you wanted requests to account/ to be sent to login.php. You need to use a [R]edirect, e.g. RewriteCond %{QUERY_STRING} (.*)RewriteRule ^login.php$ account/?%1 [R] Link to comment Share on other sites More sharing options...
driz Posted December 18, 2009 Author Share Posted December 18, 2009 Ooh, I thought you wanted requests to account/ to be sent to login.php. You need to use a [R]edirect, e.g.RewriteCond %{QUERY_STRING} (.*)RewriteRule ^login.php$ account/?%1 [R] Sorry I guess I wasn't clear enough It now redirects fine to the /account/ but it just throws a 404 error. /account/ doesn't actually exist so what should happening is the user is looking at login.php but the url says /account/ so its just making the url nicer but not actually redirecting to a directory called /account/ just making it look as though it is. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 18, 2009 Share Posted December 18, 2009 So you want login.php to redirect to the account directory that doesn't exist, and then you want requests to the account directory to load login.php?This may be a silly question, but why don't you either just use login.php, or rename login.php to /account/index.php and then just link directly to the account directory? If you have the /account/index.php file requests like /accounts/?user=1 will load the index file.In other words, what's the point of redirecting? What problem does it solve? Link to comment Share on other sites More sharing options...
driz Posted December 18, 2009 Author Share Posted December 18, 2009 So you want login.php to redirect to the account directory that doesn't exist, and then you want requests to the account directory to load login.php?This may be a silly question, but why don't you either just use login.php, or rename login.php to /account/index.php and then just link directly to the account directory? If you have the /account/index.php file requests like /accounts/?user=1 will load the index file.In other words, what's the point of redirecting? What problem does it solve?I need login.php to remain as login.php as its part of a core system that auto-updates.Essentially what I'm trying to do is the same as:domain.com/index.php?id=about becoming domain.com/about/and if the user trys to access domain.com/index.php?id=about then it auto becomes domain.com/about/But I'm wanting to do it with a file called login.php Link to comment Share on other sites More sharing options...
Synook Posted December 19, 2009 Share Posted December 19, 2009 Well, then you need both! RewriteCond %{QUERY_STRING} (.*)RewriteRule ^login.php$ account/?%1 [R]RewriteCond %{QUERY_STRING} (.*)RewriteRule ^account/$ login.php?%1 [L] Note: I'm not actually sure whether that will work. Link to comment Share on other sites More sharing options...
driz Posted December 19, 2009 Author Share Posted December 19, 2009 It redirects perfectly. But /account/ just shows 404. So I'm guessing it's trying to load a directory called /account/ rather than login.php but with the new url. Link to comment Share on other sites More sharing options...
driz Posted December 21, 2009 Author Share Posted December 21, 2009 Any updates on this? Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.