Redirect assistance needed please!

I have the following structure:

index
-buyers
-sellers
-properties
–index.php

So [noparse]www.website.com/properties/index.php[/noparse] shows a list of available properties. I need to be able to link off to something like this:

[noparse]www.website.com/properties/10290392[/noparse] and have it redirect to a file in the properties directory called showprop?id=10290392

i think my problem lies in the fact that i’m using both files in a folder called properties AND redirecting to it ala:

RewriteRule ^/?properties/([a-z0-9_]+) properties/showprop.php?id=$1 [L]

but of course it’s not working. can someone help me turn the lightbulb on?

thanks,
brian.

(Moved to Apache forum - If this isn’t a suitable place for the question click the report button to get it moved somewhere more suitable.)

That rule looks pretty much okay to me.
The ^/? at the start is only if you don’t know if you’re dealing with Apache 1.x or 2.x. If you do know and it’s 1.x, remove the ?, if it’s 2.x, remove the / and the ?

Since you indicated the variables passed to the ?id= will only contain digits (at least it looked that way to me) I’d simply use [0-9]+ instead of [a-z0-9_]+

Both of these things won’t prevent the rule from working though, so have you enabled the RewriteEngine by starting the .htaccess with


RewriteEngine On

?

Another thing could be that MultiViews is getting in the way (annoying little “feature”)
Also try this in your .htaccess


Options -MultiViews

Here is my .htaccess file (as it pertains to this issue):


RewriteEngine On
Options -MultiViews
RewriteRule ^properties/([a-z0-9_]+)\\ /properties/showprop.php?id=$1 [L]

The .htaccess file is in the root of the website.
I removed the /? that you mentioned. So I go here:
[noparse]www.website.com/properties/index.php[/noparse]

it shows a list of properties with links like so:
[noparse]www.website.com/properties/1234567[/noparse]

which I think gets rewritten to:
[noparse]www.website.com/properties/showprop.php?id=1234567[/noparse]

but when i click on the link - off it goes to my 404 page.

btw - it’s possible it could be numbers or letters.


RewriteEngine On
Options -MultiViews
RewriteRule ^properties/([a-z0-9_]+)[COLOR="Red"]\\ /[/COLOR]properties/showprop.php?id=$1 [L]

Remove the \ and / in red. The \ is incorrect in that rule, and the / is not needed (and actually sends apache on a wild goose-chase looking for /properties/showprop.php on the drive root, before it checks your web root).

I would switch the first and second rule. I’m not sure if it works this way (probably does) but I’m one for keeping rewrite stuff with rewrite stuff, and all other directives at the top of the file.

Yup that’s where it’s supposed to go :tup:

I gather you’re on Apache 2.x then?

Okay, then I would change it to [a-zA-Z0-9] to take lower case, upper case and digits in to account.

If the removal of \ and / doesn’t work, change [L] at the end of the end of the rule to [L,R=302] to make the effect of the redirect visible in the browser and see if that helps somehow.

If that doesn’t help, please post your complete .htaccess, not just the rules pertaining to this problem. Other rules / settings might be interfering too! :slight_smile:

Hot damn! That did it. THANK YOU!!!
Now I can quick banging my head and go take some aspirin.

Thank you thank you!