This would seem to be a simple .htaccess RewriteRule, yet I’m still having issues with it.
Basically, I’d like any text after the domain to be interpreted as index.php?$text, unless of course, that text is a filename.
Example:
http://domain.com/register -> http://domain.com/index.php?register
http://domain.com/images/image.jpeg -> http://domain.com/images/image.jpeg
This is what I have so far:
RewriteRule ^[A-Za-z]+$ index.php?$1
However, it’s not passing the $_GET variable to the PHP page as it should.
Thanks for any help.
EDIT I’m using PHP- so if there is a better scripting method of going about this than .htaccess, let me know.
Add the QSA flag to your rewrite rule so it would look something like
QSA (query string addition) adds the query string onto your rewrite results. so any $_GET’s will get appended onto what gets passed to your php script.
You might think about adding the L flag too, especially if thats all your trying to do with the rewrite. It tells the processor that if this rule processes its the end of the rewrite.
So it would look like
I often add NC as well, which makes it case insensitive so you don’t have to handle both upper and lower case like you’re doing in your regex.
Another thing to keep in mind is that you’re not passing $1 as a proper get var. it would be better to name the var that its coming in on. And I just noticed that you’re not creating the $1 var in the first place. Try this.
Then check it in your index.php
Hope that helps!