Redirect all traffic but "beta" sub-domain to Splash screen (mod_rewrite) - zend-framework

I'd like to redirect all my traffic to my root domain, the root domain being a Splash screen. I'd like to do this ONLY when the %{HTTP_HOST} is not beta.example.(com|es|fr).
So I've tried the following in my .htaccess file, with no luck... (infinite loop... I guess it's not getting the REQUEST_URI condition, but cannot figure out why?? I've tried almost everything)
RewriteCond %{HTTP_HOST} !^beta\.example\.com$
RewriteCond %{HTTP_HOST} !^beta\.example\.es$
RewriteCond %{HTTP_HOST} !^beta\.example\.fr$
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^.*$ / [NC,L,R=302]
At that point, I should have all my traffic but "beta" sub-domain redirected to the root domain. So now I'd like to Rewrite "backstage" the root domain with my Splash screen, following in the .htaccess file:
RewriteCond %{HTTP_HOST} !^beta\.example\.com$
RewriteCond %{HTTP_HOST} !^beta\.example\.es$
RewriteCond %{HTTP_HOST} !^beta\.example\.fr$
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ splash.phtml [NC,L]
Note: I'm using the Zend Framework, so these rules are following in the .htaccess file:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I must say, I'm stuck.
thx in advance

#bsagols
This line from Zend is going to screw you up for sure.
RewriteRule ^.*$ index.php [NC,L]
You need to put your directives above this, if not above all of the Zend stuff. If I'm understanding you correctly, try this:
RewriteCond "%{HTTP_HOST}" "!^beta\.example\.(com|es|fr)$" [NC]
RewriteCond "%{REQUEST_URI}" "!\.(js|ico|txt|gif|jpg|png|css)$" [NC]
RewriteRule ".*" "/splash.phtml" [R=302,L]

Related

How to write RewriteCond and RewriteRule for changing url www to non-www and http to https?

In Apache's httpd.conf file, how to rewrite module for making url's www to non-www and force http to https?
When I tried below, it becomes infinite redirection error
RewriteCond %{HTTP_HOST} ^www.(.*)$
RewriteRule ^(.*)$ https://example.com$1
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ https://example.com$1
or
RewriteCond %{HTTP_HOST} ^www.(.*)$ [OR]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ https://example.com$1
To redirect from www/http to non-www/https, you can use :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com%{REQUEST_URI [NC,L,R]

Permanent subdomain https:// redirection for Wildcard ssl certificate

I put inside the public_html/ .htaccess code (at the begining)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]
and https:// was forced with success.
But i put on the public_html/subdomain/ .htaccess code (at the begining)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
and the subdomain get's messy.
What is wrong about this code i put in the subdomain?
I can't do anything more. Some expertise is needed.
Thank you.
Create your new .htaccess file with the following code in your sub folder.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^demos.9lessons.info$ RewriteCond
%{REQUEST_URI} !^/demos/ RewriteRule (.*) /demos/$1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^labs.9lessons.info$ RewriteCond
%{REQUEST_URI} !^/labs/ RewriteRule (.*) /labs/$1

htaccess issue after connecting domain to subfolder

I have a problem with .htaccess. I have a website in the main server folder and a domain that leads to it (adriatic.pl). No i have made a new version of the website and put it in "adriatic_new" folder. When i run adriatic.pl/adriatic_new/public everythig works fine, but when i connect the domain (adriatic.pl) directly to the "adriatic_new" folder I get "500 Internal Server Error".
I found that it may be .htaccess problem bo how to edit it to make it work?
It looks like this:
SetEnv APPLICATION_ENV development
Allow from all
DirectoryIndex main.php
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/static/index.html -f
RewriteRule ^/*$ static/index.html [L]
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}.html -f
RewriteRule .* static/%{REQUEST_URI}.html [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)/+$
RewriteRule ^.*$ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ main.php [NC,L]
php_flag magic_quotes_qpc off
php_flag register_globals off
Ok guys (and ladies?) - problem is solved.
All I had to do was to add "RewriteBase /" in my .htaccess. So simple yet so confusing and annoying. Thanks.

Rewriting css file to controller's action

I would like to use .htaccess to rewrite http://localhost/css/file.css to http://localhost/css/generate
is it possible to do it?
it seems to not working. All I have is this .htaccess and Zend Controller css with action generate
if I go directly to localhost/css/generate I have css output but when I type localhost/css/file.css I get Not Found
this is my .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/css/file\.css$ /css/generate
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Change your htaccess to this:
RewriteEngine On
RewriteRule ^/css/file\.css$ /css/generate [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
the [L] means "last", which stops it running any subsequent rules if a match was found.
Yes. Place this in your top level .htaccess or httpd.conf and restart Apache.
RewriteEngine On
RewriteRule ^/css/file\.css$ /css/generate

Pointing Multiple Domains to Different Folders

I tried to my limit. Mod_rewrite had been such a nightmare. My last try is the code bellow and even with www.water.com working I could not make www.wind.com do the same.
In the mod_rewrite log what I get is www.wind.com (HTTP_HOST) being compared to www.water.com all the time. the rewrite never reaches the second group of lines. Someone perhaps know how to achieve that please?
RewriteEngine On
----------------------------------------------------------
RewriteCond %{HTTP_HOST} (www\.)?water\.com [NC]
RewriteCond %{REQUEST_URI} !^/zend/application/Water/ [NC]
# Excludes the redirection for files that physically exist ( -s); symbolic links ( -); and existing directories (-d).
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /water.php [NC,L]
----------------------------------------------------------
RewriteCond %{HTTP_HOST} (www\.)?wind\.com [NC]
RewriteCond %{REQUEST_URI} !^/zend/application/Wind/ [NC]
# Excludes the redirection for files that physically exist ( -s); symbolic links ( -); and existing directories (-d).
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /wind.php [NC,L]
----------------------------------------------------------
For the water group, you have two RewriteRules after your sequence of RewriteConds. The first RewriteRule is applied conditionally based upon the result of the RewriteConds.
But won't the second RewriteRule be applied to all remaining requests, even requests to the domain wind.com? Consider a request for:
http://wind.com/mycontroller/myaction
It will fail all the RewriteConds for water, but then get picked up by:
RewriteRule ^.*$ /water.php [NC,L]
Won't it?
In any case, it seems like this is better handled at the hosting level. Sounds like you want comepletely distinct ZF apps for each domain, each residing in its own folder, no cross-app sharing (except possibly external libs). In that case, just map the domains - at the hosting level - to their different folders.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} (www\.)?water\.com [NC]
RewriteCond %{REQUEST_URI} !^/zend/application/Water/ [NC]
RewriteRule ^.*$ /water.php [NC,L]
RewriteCond %{HTTP_HOST} (www\.)?wind\.com [NC]
RewriteCond %{REQUEST_URI} !^/zend/application/Wind/ [NC]
RewriteRule ^.*$ /wind.php [NC,L]
This should work IMO.