Redirect (almost) all requests to the top level url

Discussion in 'Apache' started by krispharper, Nov 28, 2012.

  1. #1
    I've looked at a lot of the other mod_rewrite questions online and tried most of them, but none seem to work for me. This is what I'd like to do.
    • Redirect all requests like http://abc.com/foobar to http://abc.com/
    • EXCEPT images and js, so requests like http://abc.com/images/foo/bar or http://abc.com/js/foo/bar should work normally
    • The URL bar should stay the same. So while http://abc.com/foobar loads http://abc.com/, the URL should read like the former
    • Ports should remain intact, so http://abc.com:8080/foobar should redirect to http://abc.com:8080
    This is what I have in my .htaccess file

    
    Options -Indexes
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/(images/.*|js/.*)$
    RewriteRule ^(.*)$ - [L]
    
    Code (markup):


    The condition is working well, and images and js files are loading fine. I thought the last line would redirect everything else to just the base domain, but I'm still getting 404 errors when I test it out.


    I don't want to use a rule like this


    
    RewriteRule ^(.*)$ http://abc.com/ [L]
    
    Code (markup):


    because the domain may be different in different deployments.

    I think I just have a poor understanding of how this works, but I'm just missing something small. Can someone help me get this sorted out?
     
    krispharper, Nov 28, 2012 IP
  2. serverexpertz

    serverexpertz Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    www.anmsaiful.net/blog/php/remove-codeigniter-index-php.html
    have a check on this and let me know if its worked
     
    serverexpertz, Dec 6, 2012 IP