Welcome to WebmasterWorld Guest from 54.205.74.11

Forum Moderators: Ocean10000 & incrediBILL & phranque

Redirecting to parent directory question

   
5:29 pm on Dec 29, 2009 (gmt 0)

5+ Year Member



When redirecting a subdirectory back up to a parent directory (restructuring), is it better to place an .htaccess in the subdirectory or do all the rewriting in the parent's .htaccess?

If I understand correctly, can I have more than one Rewritebase in an .htaccess? If yes, then what ends a block of rewrites that follow a Rewritebase? Is it the next Rewritebase?

6:56 pm on Dec 29, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I prefer to have all the rules in one file, with the most specific rules listed first.
8:10 pm on Dec 29, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



> I can have more than one Rewritebase in an .htaccess?
Yes. But rarely needed.

> If yes, then what ends a block of rewrites that follow a Rewritebase? Is it the next Rewritebase?
Nothing 'ends a block of Rewrites'. Each RewriteRule 'ends' its own RewriteConds, but each rule stands by itself and ends itself.

The 'influence' of a RewriteBase directive continues, affecting all RewriteRules which follow it, until the next RewriteBase directive is found or until the end of the file.

You should not have to use RewriteBase on a normally-configured server, and if you do, then it is likely that the RewriteBases in each .htaccess file would be the same. It's only needed when the server config includes a mod_alias Alias directive or similar that essentially injects an extra or different 'directory level' into the filepath to which your URLs resolve.

Jim

8:33 pm on Dec 29, 2009 (gmt 0)

5+ Year Member



The 'influence' of a RewriteBase directive continues, affecting all RewriteRules which follow it, until the next RewriteBase directive is found or until the end of the file.

Thanks, Jim. That better states what I was attempting to ask in the latter portion of my post.

9:22 pm on Dec 29, 2009 (gmt 0)

5+ Year Member



If the redirects were placed in a subdirectory, how is the new destination referred to without the ability to place relative paths in the rule?

Example:

If the below code's location would be in a subdirectory's (named store) .htaccess and the new intended redirect destination was in its immediate parent directory, how would this be written for the new destination while maintaining an internal rewrite? (did I ask that correctly)

RewriteRule ^index\.php/category/[^/]+/cPath/100$ http://www.domain.com/category-name-c-100.html [R=301,L] 
9:34 pm on Dec 31, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You can't specify 'path up to immediate parent' but you can specify 'path down from root-directory':

RewriteRule ^index\.php/category/[^/]+/cPath/100$ /category-name-c-100.html [L]

However, you may have trouble determining that path if your code is in a subdirectory, because the path 'seen' by RewriteRule is 'localized' to the current directory. You could use a RewriteCond to get around this, or put the code into your root .htaccess file.

Jim

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month