Welcome to WebmasterWorld Guest from 54.205.88.118

Forum Moderators: Ocean10000 & incrediBILL & phranque

rewriterule

hyphen problem

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

5+ Year Member



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

3:10 pm on Apr 6, 2006 (gmt 0)

10+ Year Member



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.

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

5+ Year Member



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?

1:18 pm on Apr 7, 2006 (gmt 0)

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



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month