htaccess redirect all but two files

Discussion in 'Apache' started by cavendano, Jun 15, 2016.

  1. #1
    I have a site that I need redirected to another URL (301) with the exception of two items.

    My .htaccess file looks like this:
    RewriteEngine on
    Options +FollowSymlinks
    RewriteBase /
    RewriteRule ^view/(.*) redirect.php?view=$1 [R]
    RewriteRule ^rss.xml$ rss.php [L]
    
    Code (markup):
    I need to keep those rewrite rules active but I need everything else redirected to another url sample.com.

    Example:
    User goes to mysite.com/view/123 they still get to see mysite.com/view/123

    Example 2:
    User goes to mysite.com then they go to sample.com
     
    cavendano, Jun 15, 2016 IP
  2. 24x7servermanagement

    24x7servermanagement Greenhorn

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #2
    Exclude the view directory in .htaccess with the following code. Put this before your other rules.

    RewriteRule ^(view)($|/) - [L]
    Code (markup):
     
    24x7servermanagement, Jun 16, 2016 IP
  3. cavendano

    cavendano Well-Known Member

    Messages:
    360
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #3
    What about the rss file. How can I exclude that one?
     
    cavendano, Jun 16, 2016 IP