RewriteRule help needed

Hi all,

This should be a really easy one, but for some reason I keep getting 404’s.

.htaccess:


AddDefaultCharset UTF-8
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)$ index.php?var=$4

The site is running under a subdirectory called /site/ on root and the .htaccess file is in there as well.

The full url to trigger this would be something like:
http://www.example.com/site/somevar1/somevar2/somevar3/32145

So basically all this will trigger index.php?var to be 32145

What the ____ am I doing incorrectly?

smf,

That looks okay to me. Have you confirmed that mod_rewrite’s enabled and usable via .htaccess? If not, check the tutorial linked in my signature.

Regards,

DK

Thanks for taking a look dklynn.

For a second there I thought that mod_rewrite wasn’t actually enabled, but the host has confirmed that it actually is and still the rewrite doesn’t do anything!

Which means there’s something wrong with the actual RewriteRule line.
However to me it looks correct!?!?

Anything else you can see?

smf,

Yes, you’ve not accounted for “site/” in your regex (assuming this is in the .htaccess in the DocumentRoot).

FWIW (not much), the - in a range definition is supposed to be the first character to avoid confusion over whether it’s a meta character or not. That said, I’ve never seen a case where having it in the last position causes any confusion (for mod_rewrite) so this is just a “word to the wise.”

Regards,

DK

@DK,

The site is running under a subdirectory called /site/ on root and the .htaccess file is in there as well.

The contents of everything including the .htaccess is in the /site/ directory, which means I shouldn’t add the “site/” into the regex, not that I havn’t tried though! :stuck_out_tongue:
…I’ve tried all combos and nothing at all works, it’s just too odd. I’m beginning to think it’s the actual server config now so will run some tests on another setup elsewhere to concur with these thoughts.

Thanks for your thoughts on the matter however!

smf,

Put this in the DocumentRoot (above sites) and remove the code from your sites directory:

RewriteEngine on
RewriteRule ^sites/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)$ sites/index.php?var=$4 [R=301,L]

When you’re satisfied that this has resolved your problem, remove the R=301 which was there only to show you that the redirection has taken place as intended.

Regards,

DK

@DK,

Would you believe that didn’t work either! :wink:

smf,

No. There must be something which we’re overlooking by assuming that it’s working.

I’ve probably already asked but have you run the test to verify that mod_rewrite is enabled (from the tutorial article linked in my signature)? Creating the three files and testing should take no more than 10 minutes.

:smiley: Are you sure you’re on an Apache 2.x server?

Regards,

DK

@DK,

After much head-ache, it seems it was a permissions thing, which I might add is much harder to find out when running mod_rewrite on a shared host where you don’t have access to all the logs.

Think it has been resolved now. (notice that first word there <–[“think”]- )

Thanks for your swift responses.