mod_rewrite question

Discussion in 'PHP' started by stephan2307, Mar 5, 2010.

  1. #1
    Hi,

    Just a quick question.

    How do I add a line to htaccess that if an url does not end with / to add one?

    example

    
    mydomain.com/contact => mydomain.com/contact/
    mydomain.com/page/subpage => mydomain.com/page/subpage/
    mydomain.com/page/subpage/subpage => mydomain.com/page/subpage/subpage/
    
    Code (markup):
    Thanks
     
    stephan2307, Mar 5, 2010 IP
  2. GreenWithEnvy

    GreenWithEnvy Active Member

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Mod rewrite will not do this for you. mod rewrite will rewrite the URL behind the scenes so to speak.:
    You would have to use a PHP or other server code to redirect the page to add the slash.

    Why are you interested in doing this anyways?
     
    GreenWithEnvy, Mar 5, 2010 IP
  3. sunlcik

    sunlcik Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi stephan2307,

    I knew what you think about.Let me help you pls :)

    You should use 301 direct at this time.
    Feel free to try this code:

    RewriteRule ^contact$ /contact/ [R=301,L]
    RewriteRule ^page/subpage$ /page/subpage/ [R=301,L]
    RewriteRule ^page/subpage/subpage$ /page/subpage/subpage/ [R=301,L]
     
    sunlcik, Mar 6, 2010 IP