Redirect https to http on ispconfig+apache - apache

I know that question has already been asked, but for some reason, no matter how I try, redirect from https to http just doesn't work. I tried my default approach to redirect (always worked perfectly fine with http to https, thought it would go that smooth the other way as well) and a few solutions from here, but no effect. For now, this is the last method I've tried:
In Apache sites-available directory, I modified relevant .vhost entry, so the changed part now looks like this:
<Directory /var/www/SOMEWEBSITE/web>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
</Directory>
<Directory /var/www/clients/client1/web1/web>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
</Directory>
Still, connecting via https://SOMEWEBSITE gives me standard apache blank site
(It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.)
I tried inserting the rewrite rules directly in VirtualHost block and modyfing site's .htaccess file (same effect as above), also tried to create VirtualHost listening on port 443 and redirecting traffic to http, but this approach gave me an SSL error. Is there any other way or something I might be doing wrong? Or is that some ISPConfig issue I am not aware of?

You could try this solution, here on stackoverflow. It is not done within ISPConfig, but I do not think there is a way to do this from within the ISPConfig GUI anyway.

Related

Enable mod_rewrite Apache 2.4 on Ubuntu 14.04

So I've gone through most of the questions on this topic, but I still seem to having issues. I can't seem to rewrite any URLs using an htaccess.
Details: Using Apache 2.4 and Ubuntu 14.04
I do have mod_rewrite enabled as can be seen by the following two pieces of information:
$: apachectl -M
Loaded Modules:
....
rewrite_module (shared)
....
$: ls /etc/apache2/mods-enabled/
.... rewrite.load ....
I tried restarting apache using the following three methods:
$: service apache2 restart
$: apachectl restart
$: apachectl graceful
And nothing is working. In order to test things fully, I added a log level in /etc/apache2/apache2.conf as follows:
LogLevel notice rewrite:trace8
Which if I understand correctly means that almost all information on rewrite should be going to my error logs, BUT I am not getting any log information.
Finally, the rewrite portion in my .htaccess is as follows:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www2.%{HTTP_HOST}/$1 [L,R=301]
I put www2 instead of www because for some reason it's already redirecting website.com to www.website.com so I'm wondering if it's the browser that's automatically doing it. Oddly, it also automatically changes website.com/index.php to www.website.com
Is there anything I might be missing that might be causing this? It seems like it's rewriting something (or it's the browser doing something), but when I try and rewrite it to a bad url for it to fail, it doesn't fail and instead goes to the proper url.
Any thoughts?
Edit
Forgot to include that, I have the following in my directory:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
So I do have AllowOverride set to All for the directory that everything lives in.
I assume that you want to force www URLs.
Now, if you're using just one domain (i.e: example.com), try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
If you have several domains over there, try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^\.]+\.[^\.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
Note that this one won't match third (or more) level domains. To deal with these, consider using RewriteCond %{HTTP_HOST} !^www\., but again, watch out for sub-domain cases.
Also watch for QSA flag in your RewriteRules, you may need to add it.

mod_rewrite all to index.php in one environment

I know there are a million of questions about this, but I've tried the solutions in other questions and haven't got it to work in my case. I'm trying to redirect everything to index.php:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This works in my local environment, but in my staging environment it fails and I get a 404 error. I've checked that mod_rewrite is enabled with phpinfo(). I've tried changing a few things like using ^(.*)$ instead of ^ and using /index.php instead of index.php
What else could be the problem?
Figured it out. It was a problem with the configuration of apache. Whoever set it up for the site I'm working on did it like this in the site's .conf file:
<Directory "/data/path/to/directory">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
# and a bunch of rewrite rules...
</Directory>
The AllowOverride None prohibits the use of .htaccess. In our local and development environments, the directory structure is different, so this code doesn't even get applied. That's why the .htaccess was working.
To solve the problem I'll either have to change the line mentioned above to AllowOverride All or add another configuration for the website I'm working on like the one above that does what I wanted to do with .htaccess.
Problems like this shouldn't come up for anyone if their environments are configured appropriately, but if anyone does run into a similar situation, check the configuration of the site in apache!

Enabling .htaccess for 302 redirects

I am attempting to create an .htaccess file on an Apache server to implement 302 redirects. Hosting is provided by BlueHost.
Right now I am testing an .htaccess file which consists of just a single line:
Redirect http://mydomain.com/?_escaped_fragment_=about http://mydomain.com/about.html
The file doesn't work. After learning more, I created an httpd.conf file, which looks like this:
<Directory />
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
One of the answers to this question (Apache 302 Redirect) suggests the following may be at issue:
mod_alias is not loaded--how do I check whether it is or isn't?
Adding the httpd.conf file may require an Apache restart. Is this possible on a shared BlueHost server?
Any advice on getting the 302 redirects to work is much appreciated. Thank you!
You can't match against the query string in a redirect, you'll need to use mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=about$
RewriteRule ^$ /about.html [L,R=302]

htaccess and rewriting

I just made a subdomain on my webside mainly becouse i want a spesific address to it.
Lets say my website is : http://website.com
And my subdomain is http://sub.website.com with its main folder in /home/username/public_html/sub/
When i enter the subdomain address the address suddently changes to http//website.com/sub/
how can i keep the subdomain address?
EDIT for Dennis:
i have a rule that directs all http://www.website.com to http://website.com
I use
RewriteEngine on
Redirect to non-www
RewriteCond %{HTTP_HOST} !^(website\.com)?$
RewriteRule (.*) http://website.com/$1 [R=301,L]
even if i comment out this the address still changes to
http://website.com/sub/
Best of regards,
Alexander
I would imagine something like this would work (not tested):
Options FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^website\.com
RewriteCond %{HTTP_HOST} ^([^.]+)
RewriteRule \?cat_id=([0-9]+)&photo_id=([0-9]+) http://website.com/$1/$2/
RewriteRule ^/(.*)/(.*)/ /%1.php?cat_id=$1&photo_id=$2 [P]
Note: according to the documentation, Options FollowSymLinks needs to
be an option you can override to get the rewrite to work.
The first RewriteCond will ensure the "webiste.com" host is not rewritten (but
domains like sub.website.com will). The second one matches anything
up to the first dot of the hostname. Both of these must succeed and if so the host
part is accessible in %1.
The first RewriteRule rewrites the args to the php script to the directory paths
(a change seen on URL on the browser). The next RewriteRule uses the [P]
flag to proxy any requests of the form /xx/yy/ to %1.php (our remembered host name)
with the args passed to the php script.
As I've stated, this is not tested, but hopefully it will get you "in the right direction".
EDIT: removed the [R] from the first rewrite rule.
Another solution is to have a Virtualhost dedicated for your subdomain (that should already be the case, if not you'll get a lot of problems) and to make this VirtualHost ignore .htaccess instructions of the master domain. You should really try to keep your subdomain configuration independant of the master domain domain configuration.
Let's say your documentRoot in the subdomain VH is /home/username/public_html/sub/, when Apache serve the index.php or index.html file or anything else in this directoy it performs a recursive search of all .htaccess in /home/username/public_html/sub/, /home/username/public_html/, /home/username/, /home/ and /. So the rules defined in your master domain (I think it's in /home/username/public_html/) are applied.
You can tell this subdomain VirtualHost to ignore all .htaccess files which are before the VH DocumentRoot by adding:
<Directory />
AllowOverride None
</Directory>
<Directory /home/username/public_html/sub/>
AllowOverride All
</Directory>
You could even remove the AllowOverride All, remove all .htaccess and put the things you have in the .htaccess of your subdomain (if you have one) directly in the <Directory /home/username/public_html/sub/> section, same effect without having Apache searching for configuration parts on the filesystem (so faster).

I'm confused with Apache vhost

I am building a web application with Zend Framework, and I need to point my app to the "public" folder of the application:
So basically when I call http://localhost/myapp
it should display http://localhost/myapp/public/
I created a virtual host file called myapp into /etc/apache2/sites-available/:
<VirtualHost *:80>
DocumentRoot /var/www/myapp/public/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/myapp/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
But it doesn't work. When I call http://localhost/myapp, it displays the directory structure of the app, and when I click on the "public" folder, then it displays what I want to be displayed by default...
I never configured vhosts before and that's as far as I got with the tutorials about it.
In your first listing, you had a different value for the Directory tag, leaving off 'public' altogether. There was also a trailing slash after 'public' in the DocRoot value, but removed on your second attempt. Not sure that made a difference, but I believe it's recommended that you don't include trailing slashes.
Also, just wondering...are you running this on a local machine? I had trouble with Skype wanting to use port 80 if I started running that before my apache server. Skype will use a different port if 80 is already used. If not Skype, there may be another app that's using port 80 and interfering. That could be why you had success on another port.
Ok I found a way somehow... I don't think it's necessary the right/best way but...
in httpd.conf (in apache2 folder):
Listen 10089
<VirtualHost *:10089>
DocumentRoot "/var/www/myapp/public"
<Directory "/var/www/myapp/public">
Order allow,deny
Allow from all
AllowOverride all
</Directory>
</VirtualHost>
My app is now accessible via localhost:10089
After enabling the rewrite mod in apache, I added the necessary .htaccess, one at the root of my app, redirecting everything to index.php (Zend framework support friendly url navigation and works that way):
RewriteEngine on
RewriteRule .* index.php
and a second .htaccess file inside my public folder to allow people to access .jpg,.ico,etc files and not being redirected to index for everything:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
Hope this will help some!