homepage Welcome to WebmasterWorld Guest from 54.161.246.212
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirecting to parent directory question
smartwork

5+ Year Member



 
Msg#: 4050886 posted 5:29 pm on Dec 29, 2009 (gmt 0)

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?

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4050886 posted 6:56 pm on Dec 29, 2009 (gmt 0)

I prefer to have all the rules in one file, with the most specific rules listed first.

jdMorgan

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



 
Msg#: 4050886 posted 8:10 pm on Dec 29, 2009 (gmt 0)

> 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

smartwork

5+ Year Member



 
Msg#: 4050886 posted 8:33 pm on Dec 29, 2009 (gmt 0)

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.

smartwork

5+ Year Member



 
Msg#: 4050886 posted 9:22 pm on Dec 29, 2009 (gmt 0)

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]

jdMorgan

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



 
Msg#: 4050886 posted 9:34 pm on Dec 31, 2009 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved