Forum Moderators: phranque
Redirect /a http://example.com /b [/b]
redirects a request for example.com/a to example.com/b, but it also redirects example.com/a/x to example.com/b/x -- Any requested URL-path that starts with "/a" will be redirected.
In addition, using two different modules as you have done here (mod_alias and mod_rewrite) means that you cannot control the order of execution of their directives. Apache .htaccess files are not executed as linear/sequential programs. Rather, each Apache module in turn scans the .htaccess file(s), executing directives that it recognizes. The order in which modules scan the .htaccess file(s) is set by the server itself. Therefore, if you wish to guarantee that your redirect is executed before your WP rewrite, then use mod_rewrite for both functions.
Finally, note the term "URL-path" that I used in the description of the Redirect directive above: The URL path for example.com/a is just "/a", and this is what should appear on the left side of a Redirect Directive. The hostname "example.com" is not present in the URL-paths examined by Redirect or RewriteRule directives.
As another comment, you can significantly speed up the WP rewrite code with a few simple changes to prevent unnecessary disk checks. On many sites, this will lead to noticeable increases in the page-loading speed.
So, with all that in mind,
[code]
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
#
RewriteEngine On
RewriteBase /
#
# Redirect /index.html requests to /other-folder/index.php
RewriteRule ^index\.html$ http://babamandir.org/other-folder/ [R=301,L]
#
# BEGIN modified WordPress
RewriteCond %{REQUEST_URI} !(\.(gif|jpe?g|png|ico|css|js)|^/index\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
#
RewriteEngine On
RewriteBase /
#
[b]#
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.babamandir\.org$ [NC]
RewriteRule ^(.*)$ http://www.babamandir.org/$1 [L,R=301]
#[/b]
# Redirect /index.html requests to /web/index.php
RewriteRule ^index\.html$ http://babamandir.org/web/ [R=301,L]
#
# BEGIN modified WordPress
RewriteCond %{REQUEST_URI} !(\.(gif|jpe?g|png|ico|css|js)|^/index\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
The site url is www.babamandir.org but the site is present in www.web.babamandir.org
There is an index.html in www folder which is used as a flyer for some events. But the main home page is the wordpress site located in www/web folder as index.php.
[edited by: jdMorgan at 11:41 pm (utc) on Oct 22, 2010]
[edit reason] De-link hostnames for readability. [/edit]
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine on
#
RewriteRule ^(index\.html)?$ http://web.babamandir.org/ [R=301,L]
# Externally redirect all direct client requests for URL-path "/index.php" to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php([?#][^\ ]*)?\ HTTP/
RewriteRule ^index\.php$ http://web.babamandir.org/ [R=301,L]
#
# Externally redirect requests for all non-blank, non-canonical hostnames to canonical hostname
RewriteCond %{HTTP_HOST} !^(web\.babamandir\.org)?$
RewriteRule ^(.*)$ http://web.babamandir.org/$1 [R=301,L]