Jump to content

Htaccess Help


driz

Recommended Posts

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

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

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

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

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

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...