Forum Moderators: phranque

Message Too Old, No Replies

Hyphen problem in .htaccess

Hyphen is giving error

         

tabish

12:23 pm on May 2, 2007 (gmt 0)

10+ Year Member



Hello All,

I have following rules in my .htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /directoryname/
RewriteRule ^([a-z¦A-Z¦'_']+)\.htm$ index.php?con=$1

The above is working fine BUT when i add Hyphen like below:

RewriteRule ^([a-z¦A-Z¦'_'¦'-']+)\.htm$ index.php?con=$1

It started giving me error. My file name contains Hyphen in between the name and I want my .htaccess file to accept that.

Can anyone help?

jdMorgan

12:32 pm on May 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The syntax is simply incorrect. Try:

RewriteRule ^([b][a-z_\-][/b]+)\.htm$ index.php?con=$1 [b][NC,L][/b]

There is no need for quotes or for the "¦" symbol as a logical OR in the string. Only the hyphen character, the "]" character, and the "\" escape character itself needs to be escaped within a "character group" delimited by "[]". Use the [NC] flag to make the [a-z] case-insensitive (it's more efficient). Use the [L] flag unless the output of this rule must be rewritten again by a later rule.

Jim

tabish

12:51 pm on May 2, 2007 (gmt 0)

10+ Year Member



Thanx a lot..

But again one problem..

sometimes my filenames are also containing brakets like:

file_(name).htm

Now these brackets are giving error :(

Regards

jdMorgan

1:12 pm on May 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, add them to the group!

^([a-z_\-()]+)\.htm$

I would advise that you review RFC2396 [faqs.org], because you can't use all characters in URLs. Best practice is to limit character use to a-z, A-Z, 0-9, period, hyphen, and underscore. And be aware that the rules are different for query strings attached to URLs. Following the standards can save *a lot* of trouble...

Jim

tabish

1:17 pm on May 2, 2007 (gmt 0)

10+ Year Member



I already did that and when i got error the i aske for the help. I made it like this

RewriteRule ^([a-z_\-()]+)\.htm$ index.php?con=$1 [NC,L]

and it is not working :(

Regards

jdMorgan

2:15 pm on May 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, it was tricky...

This rule with this exact pattern works on my Apache 1.3.x test server:


RewriteRule ^([a-z_\)\(\-]+)\.htm$ index.php?con=$1 [NC,L]

Flush your browser cache before testing any change to your .htaccess code.

Jim

tabish

2:26 pm on May 2, 2007 (gmt 0)

10+ Year Member



I tired this before.. but i didnt clear cache of my browser... so it is working now!

Regards