Forum Moderators: phranque

Message Too Old, No Replies

404 Error For RewriteRule in .htaccess file

         

ntbgl

9:01 pm on May 21, 2009 (gmt 0)

10+ Year Member



I have many links on my site using the following format:

http://www.example.com/en/?url=http%3A%2F%2Fexample2.com%2Ftest%2F

On example.com/.htaccess I have:

RewriteRule ^(.{2})/(.*)$ /links/index.php$2&lang=$1

At exmaple.com/links/index.php I have a file.

For what ever reason I get a 404 error.

However, if I change my .taccess file to:

RewriteRule ^.{2}/(.*)$ /links/index.php$1

It works fine.

Why is this not working, and are there any fixes I should make to .htaccess file, It seems sickly.

Thanks

g1smd

10:24 pm on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need to be more clear what you are trying to achieve.

RewriteRule cannot "see" parameters. You need an additional RewriteCond for that.

If this is a rewrite, you'll need the [L] flag on the end of the rule.

If you're trying to implement some sort of "static-looking" URL system, then the links on your page need to use that new format too. It is the links that 'define' URLs.

If this is some sort of redirect system, then there are other code issues to also fix.

The .{2} notation is likely incorrect. You normally use {} after [] here.

The use of .* is brutally inefficient, and likely needs a different pattern. Without knowing what it is supposed to do, i can't suggest a replacement yet.

In any explanation take great care to use the exact words like "redirect" and "rewrite" in their correct manner to explain the issue.

jdMorgan

10:43 pm on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'll take a guess at what was intended:

# Rewrite requests for URL example.com/cc/?url=xyz to filepath /links/index.php?url=xyz&lang=cc
RewriteCond %{QUERY_STRING} ^url=[^&]+$
RewriteRule ^([a-z]{2})/$ /links/index.php?lang=$1 [QSA,L]

Jim

ntbgl

12:28 am on May 22, 2009 (gmt 0)

10+ Year Member



Thank you both, your advice and reworked script helped immensely!