Mod Rewrite / htaccess question

Discussion in 'Site & Server Administration' started by pavv, Jan 1, 2013.

  1. #1
    Hello,

    I'm trying to redirect
    domain.com/test
    domain.com/TEst
    domain.com/test.html
    domain.com/test22
    domain.com/TEST.php

    to domain.com/test.html . So the redirect should work for all urls that start with test, case insensitive.

    What I have now :
    ===
    RewriteCond %{HTTP_HOST} ^domain.com$ [OR,NC]
    RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
    RewriteRule ^test(.+).\html$ "http\:\/\/www\.domain\.com\/test\.html" [R=301,L]

    I tried many things, but I can't make it working as I want.
    Thank you.
     
    Solved! View solution.
    pavv, Jan 1, 2013 IP
  2. #2
    You're kind of not making sense. Do you want to redirect domain1.com/test.php (or whatever) to domain2.com/test.html? Because you mention you want everything redirecting to domain.com/test.html but also include domain.com/text.html as an example of what you want to redirect. Very odd.

    Anyway:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/test.html [NC]
    RewriteCond %{REQUEST_URI} ^/test(.*) [NC]
    RewriteRule (.*) [url]http://domain.com/test.html[/url] [R=301,L]
    Code (markup):
     
    Last edited: Jan 3, 2013
    ryan_uk, Jan 3, 2013 IP
  3. pavv

    pavv Well-Known Member

    Messages:
    275
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    120
    #3
    Hello Ryan,

    domain.com/test.html from the list is my mistake ... sorry.
    I tested it and is working great. I made one small modification. I removed the [NC] from the first line , so it can process urls like domain.com/TesT.html

    So it looks now like :
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/test.html
    RewriteCond %{REQUEST_URI} ^/test(.*) [NC]
    RewriteRule (.*) [url]http://domain.com/test.html[/url] [R=301,L]
    Code (markup):
    Thank you very much for the help.
     
    pavv, Jan 3, 2013 IP
  4. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #4
    Happy to help. Glad it worked out for you, mate. I hope no one ripped you off for such a simple job.
     
    ryan_uk, Jan 3, 2013 IP