Forum Moderators: phranque
To do this, my sites typically use the following .htaccess located in the root directory;
# -------------------------------------------------------------
# Redirect any .html file to /keywords.php
RewriteEngine on
Options +FollowSymLinks
RewriteRule \.html$ /keywords.php [L]
# -------------------------------------------------------------
I now find I need to create a different set of pages, and do to this had intended to create a number of sub-directories with their own .htaccess files which would (so I thought), over-write the root .htaccess file and use the content of their own keywords.php .
Unfortunately, it seems that lower .htaccess files don't overwrite higher ones if they're identical in structure.
To get around this, I experimented with the following alternatives to the original .htaccess file - the first trying to limit the command to the root directory only, the second specifically excluding a named sub-directory;
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_URI}!/.*/
RewriteRule \.html$ /keywords.php [L]
-----------------------------------------------------
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_URI}!/subfoldername/
RewriteRule \.html$ /keywords.php [L]
Neither alternative works - the root directory .htaccess continues to over-ride the lower ones.
Anyone got any suggestions as to how I can work around this?
Many thanks,
Erika.
I tried changing the name of the file that's to be rewritten ("keywords.php") in the sub-folder) and adjusting the sub-folder's .htaccess file to reflect this. Let's say I call it "secondkeywords.php" .
Unfortunately, this just produces a 404 error, in which secondkeywords.php is "not found".
It seems as if the sub-folder .htaccess is being read, but then the parser is looking reverting to the root folder to find the required file - which of course isn't there.
I've temporarily solved the problem by placing secondkeywords.php in the root folder, and things seem to work OK, with both the root and sub-folder pages displaying, but I'd prefer to have things run a little more cleanly if possible, with files being called from the folder for which they're intended.
My guess is that I've missed something really small somwhere the path(s) on one or both of the .htaccess files, but I can't find it....
I've just noticed that there's a mistake in my original post, so here are the .htaccess files as I've installed them;
In the root folder:
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_URI}!/subfoldername/
RewriteRule \.html$ /keywords.php [L]
In the sub-folder:
Redirect any .html file to /secondkeywords.php
RewriteEngine on
Options +FollowSymLinks
RewriteRule \.html$ /secondkeywords.php [L]
Sorry if this all sounds confusing...
Regards,
Erika.
Perhaps you have RewriteOptions inherit set. It is rare to have this set by default, but it would cause the problem you describe. See the mod_rewrite docs for info about inherit.
Jim
In the sub-folder:
# Redirect any .html file to /secondkeywords.php
RewriteEngine on
Options +FollowSymLinks
RewriteRule \.html$ [b]/sub-folder_name[/b]/secondkeywords.php [L]
Alternatively, in the sub-folder, you could use:
# Redirect any .html file to /secondkeywords.php
RewriteEngine on
Options +FollowSymLinks
RewriteRule \.html$ [b]s[/b]secondkeywords.php [L]
I prefer the first version, though, because it is unambiguous.
Jim