homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

hyphen problem

5+ Year Member

Msg#: 5987 posted 7:42 am on Apr 6, 2006 (gmt 0)


i have a old pages and their names like


and i want to send them a variable using re write mode but i can't figure out rule...

RewriteRule ^([0-9A-Za-z])-(*.).htm$ $2.htm?var=$1

so i want my page name like below


but it doesn't work...

i think there is hyphen problem, What am I doing wrong? or another suggestions?

Please consider also i have another pages have more than 3 hyphen.




10+ Year Member

Msg#: 5987 posted 3:10 pm on Apr 6, 2006 (gmt 0)

Try using (.*) instead of (*.) - assuming this isn't just a typo in your post. Regex looks OK to me otherwise...

Add: Keep in mind that the (.*) will match hyphens, so this rule specifically may not be the best solution given the nature of your problem.


5+ Year Member

Msg#: 5987 posted 7:44 am on Apr 7, 2006 (gmt 0)


My google friendly site has a lot of pages like






or pagename.php

as you see they contain different number of hyphen.

i want to send some of them special variable for example


so their name must be change to






But long or short names cause problem while writing ReWriteRule

How can i keep page names with hyphens and add them keyworda that contain hyphen?


WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 5987 posted 1:18 pm on Apr 7, 2006 (gmt 0)

If you wish to change the URL requested from your server, you must change the URL that appears on your pages.
Then use mod_rewrite to detect those 'special' URLs, and rewrite them to your script with the additional script variable.

Something like:

# handle "view=24" case
RewriteRule ^(view-[0-9]+)-([^.]+)\.htm$ $2.htm?var=$1 [NC,L]
# handle other cases
RewriteRule ^([0-9a-z]+)-([^.]+)\.htm$ $2.htm?var=$1 [NC,L]

The [NC] flag makes character comparison case-insensitive, and is faster than using [A-Za-z] in the pattern. The [L] flag tells mod_rewrite to stop processing rules if the pattern matches and the URL is rewritten.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved