Forum Moderators: phranque

Message Too Old, No Replies

htaccess in a directory under one with another htaccess

I'd like to install WordPress within a directory

         

guarriman3

9:52 pm on Oct 27, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi.

On my Apache Server, I have this structure to host a website under '/' and a WordPress blog under '/myblog' directory:
--- root_directory/.htaccess
--- root_directory/php_stuff
--- root_directory/myblog/.htaccess
--- root_directory/myblog/php_wp_stuff

Within 'root_directory/.htaccess' file I have several RewriteRules:
--------
RewriteRule ^item/([^/]+)/ /item.php?label1=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/$ /category.php?label1=$1&label2=$2 [L]

-----------------------
which work with
http://www.example.com/item/book-10003/ and
http://www.example.com/science/maths/

However, if I try to access
http://www.example.com/myblog/ or
http://www.example.com/myblog/hello-world/

I got a 404 error. So I modififed the .htaccess:
------------------
RewriteRule ^myblog - [L,NC]
RewriteRule ^item/([^/]+)/ /item.php?label1=$1 [L]
RewriteCond %{REQUEST_URI} !^/myblog/
RewriteRule ^([^/]+)/([^/]+)/$ /category.php?label1=$1&label2=$2 [L]

-------------------
I tried to avoid 'myblog' directory to be ruled by the 'RewriteRules'. However, it works with

http://www.example.com/myblog/
but not with http://www.example.com/myblog/hello-world/

What am I doing wrong? I also tried by adding these lines at the bottom of .htaccess, but I does not work:
--------------
RewriteBase /myblog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myblog/index.php [L]

--------------------
Any tip is welcome. Thank you very much.

penders

10:42 pm on Oct 27, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hhhmm, I didn't think the mod_rewrite directives in the parent directory's .htaccess file would be processed unless
RewriteOptions Inherit
was specified in the child directory's .htaccess file?

not2easy

1:04 am on Oct 28, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Wordpress is a funny creature in the way it works with htaccess. It generates a snippet similar to what you have pasted above under
RewriteBase /myblog/

and it does not play nice with trying to apply normal htaccess rules to it. WP uses the settings you entered when you installed WP under "Settings" to determine where it is supposed to be or appear to be; but it looks in the root directory to find its functional settings.

WP looks for the envelope, it looks something like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

lucy24

1:53 am on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule ^myblog - [L,NC]

<snip>

RewriteCond %{REQUEST_URI} !^/myblog/
RewriteRule etcetera

?
If you've already intercepted all requests for /myblog with the earlier [L] rule (but get rid of the [NC]!), what's the condition for? No request for /myblog will even get this far.

I tried to avoid 'myblog' directory to be ruled by the 'RewriteRules'.

If /myblog/ is where the WP installation lives, then it will live and die by RewriteRules. Did you mean that you don't want any inherited rules from root to subdirectory?