1

I need to redirect my webpage in the likes of

/dir/script.php?a=123&b=foobar

to

/123/foobar

I've found many answers for questions like this in this site, but none of them work for my problem. The solution from this answer is almost what I need. It works fine for three parameters:

RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ /letters.php?q=$1&d=$2&t=$3 [NC]

But if I try to rewrite it for two parameters, as need in my case:

RewriteRule ^([^/]+)/([^/]+)$ /dir/script.php?a=$1&b=$2 [NC]

I get a 500 Internal Server Error. My script is not even executed. I have tested the regex in Perl and it works fine. There is nothing wrong with it, but Apache somehow refuses to accept it.

I am using the following Apache version:

Server version: Apache/2.4.10 (Debian)
Server built:   Nov 28 2015 14:05:48

Can someone help me get this working?

EDIT:

I can't see how this is a duplicate question. The referred question has no mention whatsoever of a dynamic directory based redirection. It mentions named directory redirection, but that is completely different from what I am trying to achieve.

As requested, the log from Apache shows the following:

AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

EDIT2:

It was actually re-matching the /dir/script.php and redirecting indefinitely. The solution was to add the flag END to the RewriteRule, as specified in the documentation:

An alternative flag, [END], can be used to terminate not only the current round of rewrite processing but prevent any subsequent rewrite processing from occurring in per-directory (htaccess) context. This does not apply to new requests resulting from external redirects.

Gustavo
  • 11
  • 3
  • please share some logs from apache, including error log and mod_rewrite log (level 3). More on how to produce them is here: http://stackoverflow.com/a/9632952/209270 – asdmin Jul 08 '16 at 06:56

0 Answers0