Forum Moderators: phranque

Message Too Old, No Replies

help: different .htaccess in root and subdirectory

         

zacsg

9:15 pm on Apr 5, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



apologize if it's very basic stuff, but i could not figure out. need help. thanks in advance.

i use .htaccess file to 301 redirect all URLs from [domain.com...] to [domain.com...] to avoid URL canonicalization problem. the .htaccess i put in root is:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.domain\.com [NC]
RewriteRule (.*) [domain.com...] [R=301,L]

it had been working fine for all pages in root and subdirectories...

until i added a blog/wordpress in, say, /wordpress subdirectory. i enabled the search engine friendly URL option in wordpress, then put the .htaccess file in /wordpress as instructed by wordpress admin panel:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

now the 301 redirect in /wordpress no longer works, [domain.com...] does not redirect to [domain.com...] anymore.

i tried to copy all lines in first .htaccess file (in root) and add them to 2nd .htaccess file (the one in /wordpress), tried my best to modify, still it does not work.

could someone help?

thanks.

jdMorgan

9:54 pm on Apr 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



zacsg,

See RewriteOptions [httpd.apache.org] inherit.

Jim

zacsg

10:28 am on Apr 6, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi Jim, thanks.

I added a line:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteOptions inherit
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

now when i go to [domain.com...] it gives me 404 error.

any idea? thanks.

jdMorgan

3:29 pm on Apr 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The pattern on this rule requires that *something* (at least one character) follow the /wordpress/ local-URL-path element. Therefore, a request for /wordpress/ by itself won't be rewritten:

RewriteRule . /wordpress/index.php [L]

You might want to re-code that as

RewriteRule .* /wordpress/index.php [L]

which accepts any number (including zero) of any character following /wordpress/.

See the basic regular-expressions tutorial cited in our forum charter [webmasterworld.com] for more info.

Jim