danbopes Posted October 27, 2011 Share Posted October 27, 2011 OK, I have a situation, where I want to use mod_rewrite in three places to finally end up at the url I want. Sample URL: demo1.example.com/home/index In my Document Root I have: RewriteEngine on RewriteCond %{HTTP_HOST} ^(?:www\.)?[^./]+\.[^./]+\.[^./]+$ RewriteCond "%{HTTP_HOST}%{REQUEST_URI}" !^(?:www\.)?([^./]+)\.[^./]+\.[^./]+/?\1/ RewriteRule ^(.*) %{HTTP_HOST}/$1 [C,DPI] RewriteRule ^(?:www\.)?([^./]+)\.[^./]+\.[^./]+/(.*)$ /$1/$2 In my demo1 folder I have: RewriteEngine on RewriteRule ^(.*)$ /dev/$1 In my dev folder I have (Code Igniter's rewrite): RewriteEngine on RewriteCond $1 !^(index\.php|images|user_guide|assets|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L] So the end result is that it demo1.example.com/home/index should goto /dev/index.php/home/index. This semi works, but here is where the problem comes in. If the folder "home" exists, and there is a .htaccess file in there, it will process it before the parent (Which says go into the demo1 folder), and it ends up giving a 404. Is there a way I can fix this? I've tried adding the initial Document Root into the httpd.conf file, as well as in the <Directory></Directory> tags, and I ended up getting no rewrite, and same issue respectively when I did that. How can I fix this? Quote Link to comment Share on other sites More sharing options...
danbopes Posted November 9, 2011 Author Share Posted November 9, 2011 Is this something that can't be done? I'm guessing by the lack of responses, it seems like the set order is .htaccess files first, then system wide stuff, which doesn't seem right. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 9, 2011 Share Posted November 9, 2011 It seems like you need a few [L]s in there. Know that it does not stop URL rewriting entirely - just the current pass. The rewritten URL goes back through the request handling process, and that may trigger mod_rewrite again. Without an [L] flag, the rewritten URL is tracked and other rules that were going to be processed still will be; if you're changing the paths as much as you are that may cause some rules to rewrite incorrectly. /.htaccess, handles subdomains RewriteEngine on RewriteCond %{HTTP_HOST} ^(?:www\.)?[^./]+\.[^./]+\.[^./]+$ RewriteCond %{HTTP_HOST}%{REQUEST_URI} !^(?:www\.)?([^./]+)\.[^./]+\.[^./]+/\1/ RewriteCond %{DOCUMENT_ROOT}/%1 -d RewriteRule ^ %1%{REQUEST_URI} [DPI,L] (You can use %N to refer to something caught in a RewriteCond) /demo1/.htaccess, rewrites everything to /dev RewriteEngine on RewriteRule .* /dev/$0 [L] If that still doesn't work, add some [R]s and see where mod_rewrite is trying to go. Quote Link to comment Share on other sites More sharing options...
danbopes Posted November 9, 2011 Author Share Posted November 9, 2011 I need it to chain, the problem is the order of how it rewrites stuff. For example: demo1.example.com/home/index First rewrite (In root) should say, hey, you need to goto /demo1/home/index Second rewrite (In /demo1) should say, hey, you need to goto /dev/home/index Third rewrite(In /dev) should say, hey, you need to goto /dev/index.php?/home/index Problem is this, if the folder home exists, with a .htaccess file in it, the order then becomes: First rewrite (In /home): /home/index.php?/home/index Second rewrite (In root): /demo1/home/index.php?/home/index Third rewrite (In /demo1): /dev/home/index.php?/home/index It should go like the first one, and rewrite it to the demo1 folder, before trying to look in the home folder to begin with. That's the only rule I need to have go before the others, and putting it in the server config did not do anything. Please help. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 10, 2011 Share Posted November 10, 2011 I think you missed the point of my post. Did you try what I wrote? At least added a couple [L] flags? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.