I'm currently having a lot of struggle setting up this very simple .htaccess on my website.

RewriteEngine On

RewriteCond %{REQUEST_URI} !/page
RewriteRule (.*) webroot/$1

RewriteCond %{REQUEST_URI} /page
RewriteRule (.*) pageroot/$1

I think the code is self-explanatory. I don't know why but when there is /page in my url, it still get redirected to webroot. Thanks a lot..

shareimprove this question

closed as unclear what you're asking by Yuval ItzchakovCBroeNic WortelSoner GönülAlex Char Feb 16 '15 at 15:39

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

 

1 Answer 正确答案 

It is due to your 2nd rule changing REQUEST_URI to /pageroot/.

root .htaccess:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !/(page|pageroot/|webroot/)
RewriteRule (.*) webroot/$1 [L]

/pageroot/.htaccess:

RewriteEngine On
RewriteBase /pageroot/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php?/$1 [L,QSA]


   
Your answer is right but it still doesn't work because indeed I have anoter .htaccess file in my page folder. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*) /index.php?/$1 [L] – Laurent Meunier Feb 16 '15 at 14:57
   
I'm now getting an 'The requested URL /page was not found on this server.' error. The page .htaccess is in the pageroot folder, I have no page folder. When I said page folder I meant pageroot folder – Laurent MeunierFeb 16 '15 at 15:08
   
Well sorry for the imprecision, I was reffering to the folder containing my page files, which is actually named pageroot – Laurent Meunier Feb 16 '15 at 15:13
   
ok check updated code for /pageroot/.htaccess – anubhava Feb 16 '15 at 15:24
1 
Yhea okay thanks – Laurent Meunier Feb 16 '15 at 15:34

Not the answer you're looking for? Browse other questions tagged   or ask your own question.



来自 https://stackoverflow.com/questions/28543231/htaccess-rewritecond-request-uri-not-working