How do I get two htaccess rewrite rules to 'play nice' together?

admin

Administrator
Staff member
In my website root I have the following to redirect to non www domain

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^www\.notails\.com [NC]
RewriteRule ^(.*)$ http://notails.com/$1 [R=301,NC]

in a subfolder named 'photography' I have this...

Code:
RewriteEngine on
RewriteRule ^show/([^/\.]+)/([^/]+)$ show.php?section=$1&photoid=$2 [L]

Anything inside the photography folder ignores the www removing rule. How do I get these two rules to <em>both</em> apply to folders/files within the photography folder?

Also... my root htaccess file has this...

Code:
# BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

&lt;/IfModule&gt;

# END WordPress

Could it be interfering? I have a self-hosted wordpress blog but it's not in the root of the website, it's in a subfolder called 'blog' so I don't know why this rule is in my root's htaccess file. Can/should I move it?

<strong>Edit:</strong> Just to point out, in case it isn't obvious - I'm a complete noob when it comes to htaccess and mod_rewrite stuff. Does a htaccess file in a subfolder override any htaccess files nearer to the root than it? Or do the htaccess contents combine?

<strong>Edit 2:</strong> I have tried moving the second rule to the same htaccess file as the www removing rule as per the following code...

Code:
# BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

&lt;/IfModule&gt;

# END WordPress

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^www\.notails\.com [NC]
RewriteRule ^(.*)$ http://notails.com/$1 [R=301,NC]
RewriteRule ^photography/show/([^/\.]+)/([^/]+)$ photography/show.php?section=$1&amp;photoid=$2 [L]

If I then go to one of my photography pages it resolves to the intended url (http://notails.com/photography/show/pointofayre/260 for example) but the page is a 404.

If I manually add 'www' to that it <em>undoes</em> the other rule... (http://notails.com/show.php?section=pointofayre&amp;photoid=260) and removes 'photography/' from it.