Forum Moderators: phranque

Message Too Old, No Replies

Redirect in root conflicts with sub folder

         

nickCR

8:50 pm on Dec 29, 2011 (gmt 0)

10+ Year Member



Hello All,

I am having a problem with a rule that I am hoping someone can provide some assistance on.

I have a .htaccess in the root of my site.

Then in a development directory I have that exact same .htaccess adding the directory to the rules where necessary.

The code I have is this in the root:

RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
order deny,allow


And this in the development

RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule (.*) http://www.mydomain.com/dev/$1 [R=301,L]
order deny,allow


When I type in mydomain.com/dev it redirects to: mydomain.com/dev//home/mydomain/public_html/dev

Thanks in advance for your help!

[edited by: nickCR at 9:29 pm (utc) on Dec 29, 2011]

g1smd

9:09 pm on Dec 29, 2011 (gmt 0)

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



Put all the rules in the root .htaccess file and adjust the rule patterns to suit.

Put the more-specific rules first, that's the one that tests for a specific folder in the request.

In this case, why do you need two rulesets, when both merely redirect non-www to www?

Escape all literal periods in patterns.

Your code shows "beta" and your example URL shows "dev" but you don't explain the relationship between them.

For many reasons you should use a separate sub-domain for development, not a folder off the main site.

The "order deny,allow" code is incomplete.

nickCR

9:37 pm on Dec 29, 2011 (gmt 0)

10+ Year Member



Sorry about that confusion ... beta was supposed to be dev in that example. I have edited my original post to fix that.

The order deny,allow I will just remove. Someone else did that who was 'optimizing' the file for me.

I can see how having a folder will create problems due to the fact that the .htaccess's will conflict between the root and dev.

I like doing it on the same site as it gives me an EXACT replica of the enviroment. However I guess I could just setup another domain on the same server. I would have a few items to change in the config and htaccess each time I deploy, which I was hoping to avoid ( as that can lead to problems / mistakes ).

g1smd

9:41 pm on Dec 29, 2011 (gmt 0)

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



I find that having dev.example.com and www.example.com to be less work than having www.example.com and www.example.com/dev

nickCR

9:57 pm on Dec 29, 2011 (gmt 0)

10+ Year Member



I guess at the end it depends how you setup your configs. Mine are pretty simple, however I have them setup for sub directories. It would take a bit of work but it's probably time I do that anyway.

Any interest in optimizing an .htaccess file?