cmcculloh
cmcculloh

Reputation: 48583

Problems with a simple URL rewrite (htaccess)

I can't get a simple htaccess rewrite to work.

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /?id=$1 [L]

I went to mysite.com/?id=blah expecting to end up on mysite.com/blah.html. What's wrong?

Upvotes: 0

Views: 160

Answers (1)

cmcculloh
cmcculloh

Reputation: 48583

This is not how htaccess works. It doesn't re-write the URL visible to the user, rather it looks more like an invisible re-direct.

I'm not even sure what that rewrite in the question is supposed to be doing... BUT, for explanation purposes, let's say you wanted a user to be able to go to:

mysite.com/blah/

but you wanted the server to see it as:

mysite.com/index.php?page=blah

You could do this:

RewriteRule blah/ index.php?page=blah

The user would ALWAYS SEE WHAT THEY TYPED IN. It's not going to change the URL in the browser bar (that would be a header redirect or something, which is completely different and not really related).

Upvotes: 1

Related Questions