David 10K
David 10K

Reputation: 303

URL rewriting: non-redirect but changing url

I have configured my .htaccess file for url rewriting. I'm just using the [L] flag, no [R] flag for a rule. When I'm testing it in my browser, the page is called but... with the parameter url appearing. This is what I don't want, of course.

My .htaccess file:

RewriteEngine on
RewriteRule ^testing/([0-9a-zA-z_-]+)/([0-9a-zA-z_-]+)$ http://localhost/testing/index.php?a=$1&b=$2 [L]

Is it because I'm testing it on a localhost?

Upvotes: 0

Views: 66

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

When you use a URL with a FQDN then it automatically redirects, simply because in order to internally rewrite the URI to http://localhost/... the handler at the end of the URL-file mapping processing pipeline redirects (with a 302) anyways. You either need to pick the local path for the target or if it's in a different place than the server/vhost that is processing the request, use the P flag:

Pointing to a local URI of the server/vhost:

RewriteRule ^testing/([0-9a-zA-z_-]+)/([0-9a-zA-z_-]+)$ /testing/index.php?a=$1&b=$2 [L]

Using the P flag to proxy the request:

RewriteRule ^testing/([0-9a-zA-z_-]+)/([0-9a-zA-z_-]+)$ http://localhost/testing/index.php?a=$1&b=$2 [L,P]

Upvotes: 1

Related Questions