Forum Moderators: phranque

Message Too Old, No Replies

redirect mod rewrite with sub folders .htacces

rewrite htaccess

         

bmpbraga

2:13 pm on Aug 24, 2012 (gmt 0)

10+ Year Member



Hello...

i need some help regarding htaccess and rewrite

i have the following file structure:

root
-- .htacces
-- index.php
-- some other files
-- templates
------ template1
------ template2
----------- .htaccess
----------- index.html
-----------------assets
---------------------css
---------------------img

well in my root .htaccess i have the following:

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/assets

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]


in my root index.php i have some code that on (file not found, based on my root .htaccess ) i will load a template in template1 or template2 based on information that i collect from a mysql database...

well..

in my templateX root i have one dinamic generated htaccess file that was created when the user create his account.

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* template2/$0 [L]

because template1.html files has includes files to assets/ for instance:
<link href="assets/inc/style.css" rel="stylesheet" type="text/css" />

i need to redirect those not found domain.com/assets/inc/style.css to
domain.com/templates/template1/assets/inc/style.css


if i put this on my main .htaccess ( root )
#RewriteRule ^assets/(.*) /template2/html/$0 [NC,L,NS]
it works and all includes on assets load ok..

but on .htaccess i dont know what is the template folder to redirect...so that the .htacces on template folder can redirect


sorry if it's to confuse... :(


basicaly what i want is this:

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

but if the file not found is based on *assets* i want that the system applies the .htaccess file based on the template folder... and
dont execute the rewriteRule to .*index.php/$0


Any help..

Best regards

lucy24

4:23 pm on Aug 24, 2012 (gmt 0)

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



Wait. Stop. Say that again slowly.

in my templateX root i have one dinamic generated htaccess file that was created when the user create his account


You don't mean that this happened once, by mistake. You mean that there is something calamitously wrong with your site code, so each new account creates a new htaccess file.

I don't believe you can redirect an htaccess-- especially not from within another htaccess. Redirecting would make no sense, since you don't request htaccess. It's either in your (physical) path or it isn't.

:: looking vaguely around for jdmorgan ::

Normally there are two fixes to a problem: prevent it from happening again, and deal with the ones that have already happened. But in this case you need to stop right here and do whatever it takes to stop your system from auto-generating those unwanted htaccess files. Don't waste even one second trying to come up with an after-the-fact fix other than manually deleting the ones that have already been created.