Jump to content


Photo

How to use rewrite a rule containing other characters [RESOLVED]


  • Please log in to reply
3 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 01 September 2006 - 10:49 PM

I am trying to create a rewrite rule for this
index.php?page=change-password
and
index.php?page=my_profile
I have used this
RewriteRule ^([A-Za-z0-9]+)/?$ index.php?page=$1
which i presume only allows alphanumeric characters
I have tried using
RewriteRule ^(.*)/?$ index.php?page=$1
but i lose my link to the external stylesheet so I get no style, the images aren't displayed and none of the links work
How do i change the rule to allow all character including dash and underscore
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 September 2006 - 10:54 PM

You'll want to use this:
RewriteRule ^([a-zA-Z0-9\-_]+)$ index.php?page=$1
as the rewrite rule, it also allows underscores to

#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 01 September 2006 - 11:01 PM

will this allow - (dashes) too?
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 September 2006 - 11:07 PM

Yes, \- means -

When you want to allow hyphens in rewrite rule you'll have to escape them (\-) as a hyphen to mod_rewrite has  special meaning so you have to escape it.
This:
[a-zA-Z0-9\-_]
Allows alphanumeric characters, a hyphen (-) and an underscore (_)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users