Page 1 of 1

why is this mod-rewrite not working

Posted: Mon Feb 05, 2007 10:35 am
by louie35
This code in the .htaccess file

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteRule cat/c/(.*)/km/(.*)/ cat.php?c=$1&km=$2
RewriteRule cat/c/(.*)/km/(.*) cat.php?c=$1&km=$2
is supposed to redirect to

Code: Select all

http://www.domain.tld/cat.php?c=Car_Security&km=111561
but it doesn't. It goes in a loop

Re: why is this mod-rewrite not working

Posted: Tue Feb 06, 2007 2:52 pm
by RobertGonzalez

Code: Select all

RewriteEngine on
RewriteRule cat/c/(.*)/km/(.*)/ cat.php?c=$1&km=$2
RewriteRule cat/c/(.*)/km/(.*) cat.php?c=$1&km=$2
Theoretically, the above should take this URL:

Code: Select all

http://www.domain.tld/cat/c/Car_Security/km/111561
or this URL:

Code: Select all

http://www.domain.tld/cat/c/Car_Security/km/111561/
and point that URL to

Code: Select all

http://www.domain.tld/cat.php?c=Car_Security&km=111561
That is not happening? The .*, as I understand it, means '0 or more of any single character'

Posted: Tue Feb 06, 2007 4:04 pm
by louie35
yes indeed. It doesn't work. It gives the 404 page. I have other RewriteRules also for that page below this code but I added the [L] at the end and still doesn't do it.

Posted: Tue Feb 06, 2007 5:52 pm
by RobertGonzalez
You're missing the start (^) and end ($) character. Sorry, forgot about that totally.

Posted: Wed Feb 07, 2007 1:52 am
by louie35
I have added the ^ and $ as well but still get the 404 page.
I'll have a look again into that today and let you know.

Posted: Wed Feb 07, 2007 10:31 am
by RobertGonzalez
Post your new rules so we can see them.

Posted: Wed Feb 07, 2007 10:47 am
by louie35
this is the new rule I have

Code: Select all

#cat.php page
RewriteRule ^cat/c/([^/]*)/km/([^/]*)/$ cat.php?c=$1&km=$2 [L]
RewriteRule ^cat/c/([^/]*)/km/([^/]*)$ cat.php?c=$1&km=$2 [L]

#below that there is an old rule that i need it to saty there as well

# 1 key=value pairs, eg. 
# cat.php/km/123/ --> cat.php?product=123 
RewriteRule ^(cat|reviews_seller|search|carsales|carsales_extras|carsales_dealers|car_sale_news)\.htm/([^/]+)/([^/]*)/?$ $1.php?$2=$3 [L]

# 2 key=value pairs, eg.
RewriteRule ^(cat|products_list|rating|products_details|search|carsales|carsales_dealers)\.htm/([^/]+)/([^/]*)/([^/]+)/([^/]*)/?$ $1.php?$2=$3&$4=$5 [L]
the link is created using php like this:

Code: Select all

http://www.domain.tld/cat/c/car_security/km/111561/

or

http://www.domain.tld/cat/c/car_security/km/111561
I discovered that the reason i get sent back to the home page is because on the cat.php pahe a have some code as below:

Code: Select all

if($km == "" || !isset($_GET['km'])){
	ewd_db_close($conn);//close conn
	header ('Location: '.WEB_HOST.'index.php');
                exit();
}
i commented out that code so I rule it out and now the page displayes without results as the $km value is = ""

Can not understand why.

Posted: Wed Feb 07, 2007 11:10 am
by RobertGonzalez
Try something like this. I added the ? character before the closing regular expression delimiter and added a slash to the rewrite URL.

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^cat/c/([a-zA-Z0-9-_]+)/km/([a-zA-Z0-9-_]+)/?$ /cat.php?c=$1&km=$2 [QSA, L] 
</IfModule>

Posted: Wed Feb 07, 2007 11:21 am
by louie35
That gives me a server error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.


--------------------------------------------------------------------------------

Apache/1.3.37 Server at www. domain . tld Port 80

Posted: Wed Feb 07, 2007 11:49 am
by RobertGonzalez
I'm not sure dude. Maybe look at the mod_rewrite manual for Apache 1.3 to see if it should be done differently than in Apache 2, which is what mine is.

Posted: Wed Feb 07, 2007 11:52 am
by louie35
I can not undestand why the above rule gives this error with just going to the hme page not cat.php

Posted: Wed Feb 07, 2007 12:10 pm
by louie35
why this works:

Code: Select all

RewriteRule ^(cat|products_list|rating|products_details|search|carsales|carsales_dealers)\.htm/([^/]+)/([^/]*)/([^/]+)/([^/]*)/?$ $1.php?$2=$3&$4=$5 [L]
and this doesn't

Code: Select all

RewriteRule ^cat/c/([a-zA-Z0-9-_]+)/km/([a-zA-Z0-9-_]+)/?$ /cat.php?c=$1&km=$2 [QSA, L]

Posted: Wed Feb 07, 2007 1:08 pm
by nickvd
I've given up with .htaccess based clean url's. I've started to send anything and everything (save certain things) to index.php and just deal with the parameters in php myself...

Code: Select all

#Options -Indexes -MultiViews #this may or may not be needed...
RewriteEngine on
RewriteCond $1 !^(index\.php|img|robots\.txt|css) # match on anything except whats in the brackets
RewriteRule ^(.*)$ index.php/$1 [L] #and send it all to index.php