devunwired
devunwired

Reputation: 63303

.htaccess to partially redirect index requests

I'm doing some work for a friend on their website, and while we are working on the new site I would like to set up their .htaccess file to redirect users with the following rules:

This is probably a simple request, but I have no experience with the rules language that .htaccess uses.

Thanks in advance!!

Upvotes: 1

Views: 114

Answers (2)

Jon Lin
Jon Lin

Reputation: 143906

  • Redirect any requests to / or /index.html to a subdirectory (e.g. both http://example.com/ and http://example.com/index.html should redirect to http://example.com/legacy/index.html)

    RewriteEngine On
    RewriteRule ^(index\.html)?$ /legacy/index.html [L]
    
  • Allow direct requests to index.php to pass through without redirect (e.g. http://example.com/index.php)

    RewriteRule ^index\.php$ - [L]
    
  • If possible, requests to a second subdirectory get redirected to index.php (e.g. http://example.com/beta/ redirects to http://example.com/index.php)

    RewriteRule ^beta/?$ /index.php [L]
    

These would all go in the htaccess file in your document root. If you actually wanted to redirect the browser so that the URL in the address bar changes, include a R=301 in the square brackets: [L,R=301]. If when you say "requests to a second subdirectory get redirected to index.php" meaning "any subdirectory", then the rule needs to be changed to:

RewriteRule ^([^/]+)/?$ /index.php [L]

Upvotes: 1

akhilantony
akhilantony

Reputation: 1

i kind of did the reverse with codeigniter ...

    RewriteEngine On    
    RewriteBase /myproject
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

    $config['base_url'] = 'http://localhost/myproject/';
    $config['index_page'] = '';

hope this helps

Upvotes: 0

Related Questions