1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Mod rewrite help

Discussion in 'Apache' started by kdn1, Jan 8, 2020.

  1. #1
    Hi all,

    I have a requirement to change all underscores to dashes, well I have achieved that with these two lines:
    RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
    RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,R=301]

    However now I need to restrict these rules to only apply to a certain page "help.php" (its in the root directory)

    I thought this might do the trick:

    <If "%{REQUEST_FILENAME} ^help/.php$">
    RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
    RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,R=301]
    </If>

    But that throws a 500 error. can anyone provide some help on how to achieve this?
    SEMrush
    thanks!!
     
    kdn1, Jan 8, 2020 IP
    SEMrush
  2. Michael_version_2

    Michael_version_2 Peon

    Messages:
    7
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    3
    #2
    Hi. What happens if you change <If "%{REQUEST_FILENAME} ^help/.php$"> to <If "%{REQUEST_FILENAME} ^help\.php$"> (note the slash in help.php)? I don't really know <if> rules. I assume they are the same as RewriteCond?
     
    Michael_version_2, Jan 11, 2020 IP