Forum Moderators: coopster & phranque

Message Too Old, No Replies

.htaccess mod rewrite

how to create regex for these case ?

         

wharsono

12:06 am on Jul 15, 2002 (gmt 0)

10+ Year Member



Sorry i Have bad english..

How to write regex that all request from browser contain such as

[rentacar.com...]
[rentacar.com...]

that all those request serve by cars.php

Im tryng to create .htaccess like this but seems doesnt works :

RewriteEngine on
RewriteRule ^/\(cars-*)/\*$ /cars.php?uri=%{REQUEST_URI}

I got internal server error on apache. error logs is :

[Mon Jul 15 19:19:02 2002] [alert] [client 127.0.0.1] c:/inetpub/wwwroot/i/.htaccess: RewriteRule: cannot compile regular expression '^/\(cars*)/\*$'
Apache server shutdown initiated...

Any idea?

jdMorgan

12:39 am on Jul 15, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



wharsono,

It wasn't clear exactly how you wanted to pass the page number to php, but here
are a couple of examples:

This rule
RewriteEngine on
RewriteRule ^cars-(.*)$ cars.php?uri=$1 [L]
will rewrite
[rentacar.com...]
to
[rentacar.com...]

This rule
RewriteEngine on
RewriteRule ^cars-(.*)/.*$ cars.php?uri=$1 [L]
will rewrite
[rentacar.com...]
to
[rentacar.com...]

This rule
RewriteEngine on
RewriteRule ^cars-(.*)/(.*)$ cars.php?toppage=$1&subpage=$2 [L]
will rewrite
[rentacar.com...]
to
[rentacar.com...]

Note that "." means "any character" and "*" means "any number of the preceding
character". Wildcards and escaped characters are not the same as in scripting
languages. Take a look at www.apache.org and look up the mod_rewrite module
of Apache Server. There is a lot of information there. Also, a search for
"regular expressions regex" on a top search engine will turn up many syntax and
usage guides for the regular expressions used by mod-rewrite.

Note: If none of the above rules work, try escaping the "-" in "cars-" by
putting a "\" in front of it. Warning - I didn't test these!

Hope this helps!

Jim

wharsono

12:05 pm on Jul 16, 2002 (gmt 0)

10+ Year Member



Thank you for your help by giving me some example and tips which is helping me so much in learning this things more further .

actually what I mean is : if there is a request from browser, like below :
[xyz.com...]
its mean
[xyz.com...]

or

[xyz.com...] its mean
[xyz.com...]

because I will take the URL request point as parameter for the database

and through your example, I have change my script become:

RewriteEngine on
RewriteBase /
RewriteRule ^cars-(.*)$ /cars.php?uri=%{REQUEST_URI}

once again thank you