Redirect all accessible URL's to only one specific subdomain - .htaccess

I have my working worpress domains, subdomain and alias working normally and locate at root web server "www/".
htpps://domain.com
htpps://domain.net
htpps://en.domain.net
Later I decide to install a support web application in same server in folder "www/support/".
Setting this support app I needed to set one domain or subdomain, and I set "support.domain.com".
After last step I realise that all the following URL's could access to the support app:
htpps://domain.com/support
htpps://domain.net/support
htpps://en.domain.net/support
htpps://support.domain.com/support
htpps://support.domain.net/support
Since this support app doesn't work correctly with differents domains or subdomains from the main one that was set initially ( that was: "support.domain.com" ), I'm trying to redirect all to one unique subdomain: "support.domain.com".
The file ".htaccess" locate in support app folder ("www/support/.htaccess") still empty, all rewrite rules I try didn't worked, due my low knowledge.
How could I redirect all accessible URL's to only one "support.domain.com"?
or
Block all access to this folder "www/support/index.php" that are not "support.domain.com"?
I found and try lots of similar questions but none work correctly or give too many redirections.

in support.htaccess, you can use the following rule
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.+ http://support.domain.com/ [L]

After several time pass over, I finally locate the problem, double quotes was “ instead of "
This small details was creating problem in every .htaccess file in my host, after this correction all working correctly and it reach support/.htaccess now.

Related

Can't get my Zend Framework 2 project working on hosting server

Currently I am developing a webshop in PHP. For this I use the Zend Framework 2.
All of my routes exist of a locale i.e. "nl_NL" or "en_EN", followed by a controller and an action www.mydomain.com/nl_NL/profile/login. Look here for an example of a route used in my project. This one belongs to the Profile Module: http://pastebin.com/jmim47w8.
If the visitor has no account, and no Cookie is set, the locale variable will first be set to the variable retrieved from the following function:
locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE'])
If a cookie is set that value will be used.
On the other hand, if a user does have an account and is logged in, the variable used will be retrieved from the user's profile.
My entire script does work on a localhost. However, on the server it doesn't.
When loading the page nothing gets shown. I have checked the error logs and couldn't find anything. However, when i place /nl_NL/ or any other locale that meets the requirements of the "locale route" regex in the url manually, it does work.
My first thought was that the url_rewrite apache module was not installed or activated, but since other websites use this module as well, and they are on the same server this doesn't seem logical. Of course I did try to check wether it was enabled by running some scripts, but to no avail. Since our server is setup to not allow shell scripts to be ran, or to check wether apache modules are enabled using phpinfo() it's quite hard to make sure.
I have tried to verify that my .htaccess file is correct, but I'm pretty much a noob at .htaccess. This is my .htaccess:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
To see what my IndexController looks like look here: http://pastebin.com/AEgm3Jmk.
All in all, I would really like to know how to get a Zend FW 2 project to work on a hosting server while still using url rewrite or any other way that makes it possible to use locale variables.
If there is something missing from this post that is needed to help me further, I will be happy to post it.
I have solved the problem, everything is working fine right now.
I found the problem to be in my local.php config file. The problem was
an error within this file, so it was actually a write error ( corrupt file ).
#Alex thanks for the help though, appreciate it.

Silverstripe mod_rewrite issue (I think)

A site I've been working on, which has been working fine on my local dev and live dev environments is giving me issues when I try to deploy it to a live server (the client wants to host it with their existing hosting provider).
I uploaded the site to the server and updated the database config as I have done many times before on both my and other's servers without issue. This time, however, I was presented with:
SilverStripe Framework requires a $databaseConfig defined.
When I removed the .htaccess file from the root folder, the site appeared, however, all the URLs appeared like so:
www.domain.com/index.php/page_name
After a few searches, I came across a solution to the index.php issue; to add the following to my _config file
Director::setBaseURL('/');
I did this and the URL's appeared correctly, however navigating to them would give me a 404.
I reinstated the htaccess file and narrowed it down to this block:
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule .* framework/main.php?url=%1 [QSA]
When this is in place, I get the database config error mentioned above, when it's not there, my urls produce 404s
Does anyone have any insight as to what can be going on here? I've had a lot of back and forth with the host and he's not very knowledgable and can't offer any advice and I'm no genius when it comes to this side of things.
I'll assume you are using SilverStripe 3.1+ so the Director config could/should be placed in your YAML config file (the static will be deprecated):
Director:
alternate_base_url: '/'
Although this helps mainly on issues with base_tag.
The main ModRewrite issue might however be solved by adding a RewriteBase:
RewriteEngine On
RewriteBase '/'
You can use '/' or the folder SS is installed in if not the public root. This is usually automatically handled by the SilverStripe installer by checking $base = dirname($_SERVER['SCRIPT_NAME']); and other little things. Check install.php5 line 1483, you might be able to use this to figure out your RewriteBase.
If that doesn't work, try a fresh install instead of copying to the server your local install.
Do you use a _ss_enviroment.php to define your database config details? I had a similar experience like from in a project i migrated from SS 2.4 to 3.1.2.
Set this in your site _config.php
// Use _ss_environment.php file for configuration
//Please note that your system should have a file, _ss_environment.php, with database connectivity data,
require_once("conf/ConfigureFromEnv.php");
global $database;
$database = '';
I hope this helps

Using .htaccess to redirect all requests from subdomain to main domain

I have a hobby website for a number of different projects and want each project to have it's own subdomain, like foo.domain.com, bar.domain.com etc.
I use Drupal with the Domain Access module, meaning all subdomains should point to the base installation of Drupal, and then the module recognizes what subdomain the request comes from and serves a page according to that.
Now, since this is just a hobby project, I keep it on a free shared hosting account, which means a few limitations:
No wildcard subdomains.
Each subdomain is linked to a subdirectory with the same name, for example domain.com goes to /public_html/ and sub.domain.com goes to /public_html/sub/ The hosting forces this.
I can't create symlinks.
I have limited space and databases, meaning I can't just make a new installation for each project. (Hence the Domain access module)
My domain registrar (Godaddy) doesn't play nice with shared hosting. I tried hosting the DNS with them and doing a wildcard A record to my hosting server, but it didn't work, and Godaddy don't allow wildcard CNAME records for some reason...
It seems the only option left for me is some .htaccess magic.
I need a .htaccess file to put in the subdomain director(y/ies) to tell apache:
The data is in the root web directory
To not change anything else, so that the Drupal module knows what subdomain was requested and the user still sees "sub.domain.com" in the browser window.
Thankful for your help!
TL;DR
How can I tell Apache to use the data from another directory (i.e. /public_html/ instead of /public_html/subdomain/) WITHOUT making a redirect or any changes to the headers? HTTP_HOST needs to be intact.
Thanks!
Try this:
http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
try this
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com%{REQUEST_URI} [R=301,L]
try this.
RewriteEngine On
RewriteCond %{HTTP_HOST} sub\.example\.com$ [NC]
RewriteRule ^sub/(.*)$ $1 [L]
Not sure if it will work, because I don't know how your host configured to server to map the subdomains to a different folder.
Otherwise you could try the Proxy flag, but that will not set the correct http_host variable in php.
Are you sure Drupal doesn't have a different method of doing multiple installs. I know WP did have a option to use a prefix for all table-names so multiple installs can coexist, using the same database, as long as they use different prefixes. Not sure how big a Drupal install is, and what amount of diskspace your host provides.

htaccess selective redirect

I am trying to redirect all sub-directory pages to main directory, except of a few pages (e.g. (somepage1.html).
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(de|ru)/somepage1.html
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/(.*)$ /$2 [R=301,L]
Everything working except de/somepage1.html is redirected to home page (/), which is not acceptable. I wont it not redirected at all.
How can I achieve it
Thanks1
Well above rules are clearly excluding de/somepage1.html URL so it is most likely some other rule that is redirecting de/somepage1.html to /. Are you using wordpress or some other CMS tool by any chance? That might have its own rules in .htaccess file, check that please.
Also it would help to check web server's access log when this redirection happens.
the code I provided is working perfectly, so if somebody looking for this kind of a solution can use it without a fought.
The reason for not working is that my website were keeping cash and therefore was not renew frequently.

Need to redirect to true root folder

I am running a website on MAMP, and the root is http://localhost/sandbox
When I have links that link to, for example - /calendar
it directs them to localhost/calendar, I want it to redirect to localhost/sandbox/calendar
What would I have to do in htaccess to get it to redirect everything to localhost/sandbox/ as the root?
You would usually change the application or site that generates the links, and have that add the /sandbox to the URL.
If that's not possible, putting this into the web root directory (the one above /sandbox) should do:
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{REQUEST_URI} !^/sandbox # If URL does not start with /sandbox...
RewriteRule (.*) /sandbox/$1 # Add /sandbox/ in front of it
(if it's easier to achieve with Alias, Apache Gurus, feel free to add your solution, but I couldn't get Alias to work for this scenario.)
However, this solution will make any other directory besides /sandbox inaccessible. You may want to re-think your Virtual hosts structure!

Resources