This is a discussion on help with apache rewrite rule within the Apache Web Server forums, part of the Web Server and Related Forums category; I need to be able to give users URLs that look like this... http://www.domain.com/ABC123/page.php .......
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I need to be able to give users URLs that look like this...
http://www.domain.com/ABC123/page.php ....and have the apache rewrite engine change them to look like this... http://www.domain.com/page.php?account=ABC123 I'm not really sure how to do this. To further complicate matters, the users can also leave off the page like this... http://www.domain.com/ABC123/ ....and should be redirected to... http://www.domain.com/index.php?account=ABC123 Can anyone give me examples that show how to go about this? Or at least point me at a resource that shows how to do these sort of things? Thanks in advance |
|
|||
|
William Krick wrote:
> I need to be able to give users URLs that look like this... > > http://www.domain.com/ABC123/page.php > > ....and have the apache rewrite engine change them to look like this... > > http://www.domain.com/page.php?account=ABC123 RewriteRule ^/([^/]*)/page.php$ /page.php?account=$1 > > > I'm not really sure how to do this. > > > To further complicate matters, the users can also leave off the page > like this... > > http://www.domain.com/ABC123/ > > ....and should be redirected to... > > http://www.domain.com/index.php?account=ABC123 RewriteRule ^/([^/]*)/ /index.php?account=$1 > > > Can anyone give me examples that show how to go about this? > Or at least point me at a resource that shows how to do these sort of > things? > Visit http://httpd.apache.org/ and read up on RewriteRule for your version of Apache. Learn that regular expressions are fun. > Thanks in advance > Good luck, Jim |
|
|||
|
Hmmm. I think that I didn't make my original example clear enough.
"page.php" can be *anything*.php. I need to capture everything between the last slash and the ".php" and put that into a variable too, like the account number. I know a little of regular expressions from using AWK back in college. Let's see how much I remember. Disecting the example you posted... RewriteRule ^/([^/]*)/page.php$ /page.php?account=$1 ^ means the beginning of the line / followed by a slash ( ) followed by *something*, $1 that is [^/] one or more of anything that is NOT a slash / followed by a slash page.php$ followed by page.php at the end of the line. So tell me if this is what I need to handle... http://www.domain.com/ABC123/foo.php ....where foo can be anything: RewriteRule ^/([^/]*)/([^/]*).php$ /$1.php?account=$2 Am I close? |
|
|||
|
Am Thu, 11 May 2006 13:30:15 -0700 schrieb William Krick:
> Hmmm. I think that I didn't make my original example clear enough. > "page.php" can be *anything*.php. > > I need to capture everything between the last slash and the ".php" and > put that into a variable too, like the account number. > > I know a little of regular expressions from using AWK back in college. > > Let's see how much I remember. Disecting the example you posted... > > RewriteRule ^/([^/]*)/page.php$ /page.php?account=$1 > > ^ means the beginning of the line > / followed by a slash > ( ) followed by *something*, $1 that is > [^/] one or more of anything that is NOT a slash * = zero or more of anything .... > / followed by a slash > page.php$ followed by page.php at the end of the line. > > So tell me if this is what I need to handle... > > http://www.domain.com/ABC123/foo.php > > ...where foo can be anything: > > RewriteRule ^/([^/]*)/([^/]*).php$ /$1.php?account=$2 > > > Am I close? Yes, you are: RewriteRule ^/([^/]*)/([^/]*).php$ /$2.php?account=$1 will do it. Kind regards Ulrich |
| Thread Tools | |
| Display Modes | |
|
|