homepage Welcome to WebmasterWorld Guest from 54.197.111.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
rewriterule
hyphen problem
ACCelerate




msg:1500790
 7:42 am on Apr 6, 2006 (gmt 0)

Hi,

i have a old pages and their names like

something-like-this.php

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

var-something-like-this.php

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.

Thanks

 

ryan26




msg:1500791
 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.

ACCelerate




msg:1500792
 7:44 am on Apr 7, 2006 (gmt 0)

Hello,


My google friendly site has a lot of pages like

page-name-page-name-page-name.php

or

page-name-page-name-page.php

or

page-name-page.php

or pagename.php

as you see they contain different number of hyphen.

i want to send some of them special variable for example

page-name-page-name-page-name.php?var=view-24

so their name must be change to

view-24-page-name-page-name-page-name.php

or

view-24-page-name-page-name.php

or

view-24-page-name.php

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?

jdMorgan




msg:1500793
 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.

Jim

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