Jump to content

Archived

This topic is now archived and is closed to further replies.

AdRock

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

Recommended Posts

I am trying to create a rewrite rule for this
[url=http://index.php?page=change-password]index.php?page=change-password[/url]
and
[url=http://index.php?page=my_profile]index.php?page=my_profile[/url]
I have used this
[code]RewriteRule ^([A-Za-z0-9]+)/?$ index.php?page=$1[/code]
which i presume only allows alphanumeric characters
I have tried using
[code]RewriteRule ^(.*)/?$ index.php?page=$1[/code]
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

Share this post


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

Share this post


Link to post
Share on other sites
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 (_)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.