1

I have two different things I want to happen in the case of two different types of URI's but I can't seem to stop the second case from executing where the first case has already been accepted.

Here's an example:

abc.com
abc.com/asdf
abc.com/en/asdf
abc.com/zh-cn/asdf/asdf

Should all be directed to this RewriteRule:

RewriteRule ^(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /index.php?lng=$1&tpl=$4 [QSA,L,NC]

Part 2:

abc.com/myadmin/
abc.com/myadmin/asdf
abc.com/myadmin/en/asdf
abc.com/myadmin/zh-cn/asdf/asdf

Should all be directed to this RewriteRule:

RewriteRule ^myadmin/(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /myadmin/index.php?lng=$1&tpl=$4 [QSA,L,NC]

The way I've been attempting to acheive this is by stacking the conditions like this:

RewriteCond %{REQUEST_URI} !^/myadmin/
RewriteRule ^(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /index.php?lng=$1&tpl=$4 [QSA,L,NC]

RewriteCond %{REQUEST_URI} ^/myadmin/
RewriteRule ^myadmin/(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /myadmin/index.php?vlng=$1&tpl=$4 [QSA,L,NC]

But no matter what I do, both rules still execute. Maybe I'm doing this right and the secondary execute is occurring further down in the php templates, I'm not sure. I just need to know if what I have done so far looks good, ty all.

Vince
  • 910
  • 2
  • 13
  • 29

2 Answers2

1

Replace this condition:

RewriteCond %{REQUEST_URI} !^/myadmin/

With these 2:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 

Putting it all together:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^myadmin/(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /myadmin/index.php?vlng=$1&tpl=$4 [QSA,L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(([a-z]{2})(-[a-z]{2})?)(/([a-z0-9-\./]*))?$ /index.php?lng=$1&tpl=$4 [QSA,L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • This doesn't appear to solve my problem, even if I delete the second set of conditions all together and hardcode my URI to the /myadmin/ dir it still calls my /index.php file at the root of the server. Is the RewriteBase / critical in your example to function properly? I've never seemed to require it before. – Vince Aug 07 '13 at 00:28
  • First you have to make sure that above .htaccess is directly under DOCUMENT_ROOT. Pls dump your complete .htaccess in your question and tell me for which URI this code didn't work so that I can also test from my end. – anubhava Aug 07 '13 at 05:58
  • The complete .htaccess file is almost 260 line long and it is in the DOCUMENT_ROOT. If I use the code you have suggested above while attempting to access my admin area the other RewriteRule is also executed and I can tell because the other rule points to code which updates cookies found on the public side of my site. The only way I can stop my cookies from being update is to remove the second part of the code you have posted above which breaks the public side of my site. I need another way to do this which won't allow both conditions to execute. – Vince Aug 07 '13 at 06:30
  • Well something is not right in your setup then. Since `/index.php` should be a valid file and that will make `RewriteCond %{REQUEST_FILENAME} !-f` to fail and skip execution of your 2nd rule. – anubhava Aug 07 '13 at 10:38
0

Ok I found the problem, it was partly my fault for assuming the Clear Cache extension in my Chrome browser only worked on a single tab at a time and a default setting in that extension that automatically reload all tabs after the extension was activated.

Like most developers I have between 5-10 tabs open in my browser at any given moment while developing to access testing areas of my site, development tools and technical resources. When I work on code I generally do all my cache cleaning by hand personally so that I know it is really done, in this case I chose to add a new extension to my Chrome browser called 'Clear Cache' to help me take care of this a little faster because I was making a lot of small changes which I needed to make clean tests of each time. What I didn't realise was that when you activate the extension it also cleans the cache of all your other tabs as well. I also didn't notice the default setting that is set to automatically reload them all after the cleaning is performed. Because it also doesn't show you that it is reloading all these other tabs visually I had no idea it was reloading a tab that I had open to the main page of the site I was working on that was responsible for loading cookies.

To summarize while I worked on my site, in one tab, testing changes to my admin area I kept seeing cookie updates that could only come from the public side of my site and it kept making me think there was something still wrong with my htaccess changes. I realized, after two days of troubleshooting, the handy dandy extension I'd added to help make things easier was actually reloading all the tabs in my browser without letting me know and all those other calls were responsible for the continual return of cookies that could only be generated by the public side of my site which was confusing the hell out of me. I'll be going to go back to clearing my cache by hand again after this.

Vince
  • 910
  • 2
  • 13
  • 29