Reputation: 4076
Here is the url that I have that works:
example.com/php/statePage.php?region_slug=new-york-colleges
Here is what I am trying to get the url to appear as:
example.com/new-york-colleges.html
I have tried several things so far and I think I am getting close but this is my first PHP / MySQL site and first time using .htaccess.
Here is my .htaccess so far:
RewriteEngine on
RewriteRule ^/([^/.]+).html?$ php/statePage.php?region_slug=$1 [L]
Any help would be greatly appreciated. If you could explain what I was missing or what I did wrong, that would help me more... I am trying to learn how to do this and simply giving me the cut and paste method will only help me today.
THANK YOU, this means a lot to me!
Upvotes: 0
Views: 154
Reputation: 792
RewriteEngine on
RewriteRule ^([^/\.]+)\.html/?$ php/statePage.php?region_slug=$1 [L]
Two things to point out:
When .
is used in rewrite syntax, it represents any character. So your current rule says replace anything that's NOT any character, followed by '.html'. To work around this, escape your dot like so \.
. There are several special characters in rewrite syntax such as this. It would benefit you to pay attention to them.
Second, I'm not sure if this is rewrite canon or not, but I've never personally used forward slashes at the start of a rewrite rule before, and that may or may not impact the rule itself. Any user with a clarification on this is encouraged to reply.
EDIT: The following characters are marked as special characters in rewrite syntax (and all regular expressions, for that matter), and as such, need to be escaped with a backslash \
in order to be used literally - [\^$.|?*+()
Also, you may find this reference useful in further understanding the correct syntax for regular expressions.
Upvotes: 1