Redirect from HTTPS to HTTPS of other website - redirect

I have read some other questions which are doing almost the same stuff but I wasn't able to replicate the same.
https://serverfault.com/questions/167395/redirect-https-to-another-https
Apache HTTPS to HTTPS Redirection
(I have tried both)
When users click or enter the https:// version I want to redirect my website (which is https://website1.com) to another website (https://website2.com).
What I have achieved till now is when the user clicks on http://website1.com version of the site, they are getting redirected to https://website2.com but when https://website1.com it loads the https://website1.com, no redirection happens.
I'm using Apache HTTPD and below is my httpd.conf file entry:
<VirtualHost *:80>
ServerName website1.com
ServerAlias www.website1.com
RewriteEngine On
RewriteCond %{ENV:HTTPS} on
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(.*)$ https://website2.com/$1 [R=301,L]
RedirectPermanent / https://website2.com/
</VirtualHost>

Seems OR condition is missing for HTTP.
The following code should work, although I haven't tested it.
<VirtualHost *:80>
ServerName website1.com
ServerAlias www.website1.com
RewriteEngine On
RewriteCond %{ENV:HTTPS} [OR]
RewriteCond %{ENV:HTTP} on
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(.*)$ https://website2.com/$1 [R=301,L]
RedirectPermanent / https://website2.com/
</VirtualHost>

Related

Apache2 - Reverse Proxy: Restrict Proxy Pass to just one special URL

At the moment I have the following code in my Config of Apache2.
So on every request on
http://[ExternalAdress]/vis/vis
is redirected to
http://[InternalAdress]/vis
<IfModule mod_proxy.c>
ProxyRequests off
RewriteEngine On
redirectmatch ^/vis/$ /vis/
rewritecond %{REQUEST_URI} ^/vis/
rewriterule (.*) $1 [PT]
rewritecond %{HTTP_REFERER} http://[ExternalAdress]/vis/
rewriterule ^/(.*) /vis/$1 [PT]
ProxyPass /vis/ http://[InternalAdress]:8082/ nocanon timeout=10
ProxyPassReverse /vis/ http://[InternalAdress]:8082/ timeout=10
</IfModule>
<IfModule mod_proxy.c>
RewriteEngine On
Redirectmatch ^/socket.io$ /socket.io/
RewriteCond %{REQUEST_URI} ^/socket.io/
RewriteCond %{QUERY_STRING} transport=websocket
RewriteRule ^/(.*) /wss/$1 [PT]
ProxyPass /wss/ ws://[InternalAdress]:8082/ timeout=1200 Keepalive=On
#ProxyPassReverse / ws://[InternalAdress]:8082/
</IfModule>
But now I want to change my code so that only one specific URL will be redirected and others not.
For example:
http://[ExternalAdress]/vis/vis/index.html?abc#123 shall be redirected to
http://[InternalAdress]/vis/index.html?abc#123
but
http://[EnternalAdress]/vis/vis/index.html?def#456 shall not be redirected to anywhere
How has my code to be changed to be sure that only one specific URL will be redirected and others not?

redirect doamin and sub domains to https://www

My website is written in CodeIgniter and hosted on Ubuntu 16.04
I have to redirect all domain and sub domains to https://www.
Ex: I want like this
http://com-download.live --> https://www.com-download.live
http://youtube.com-download.live --> https://www.youtube.com-download.live
http://vimeo.com-download.live --> https://www.vimeo.com-download.live
Note: Please suggest me the better way, where should I place redirect rules, In apache virtual host or in .htaccess ?
My Current code placed in virtual host is:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)com-download\.live [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}$1 [R=301,L]
But it's not working properly
http://www.com-download.live redirecting to http://www.www.com-download.live
In my opinion redirecting by htacces ll be easier, sample like:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$
https://www.yourdomain.com/$1 [R,L]
But take into the possibility of editing this in the future it would be better to set the redirection via the server, less emergency and easier to observe if you have many more domains
Example on console:
sudo nano /etc/apache2/sites-available/000-default.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

ISPAI Rewrite 301 Redirects / SEO URL Canonicalization on Windows Server

I am new to working on a windows server and have been made aware that it is setup for ISPAI Rewrite.
I have tried creating a httpd.ini file and a .conf file with possible redirects but nothing is working.
Could someone show me how to create the correct file and then rewrite the following:
http://aspectexhibitions.co.uk/
Should redirect to:
http://www.aspectexhibitions.co.uk/
--
http://www.aspectexhibitions.co.uk/index.php
http://aspectexhibitions.co.uk/index.php
Should redirect to:
http://www.aspectexhibitions.co.uk/
Done...
[ISAPI_Rewrite]
#Redirect Non WWW to WWW
RewriteEngine on
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]
#Redirect index.php to root
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ http://www.aspectexhibitions.co.uk/ [NC,R=301,L]

Zend MVC - htaccess redirect

All,
My Zend framework Application structure is like this:
billingsystem
-application
-design
--css
--struct.css
--icons
--styles
--images
--js
--common
--thirdparty
-public
--index.php
--.htaccess
-library
-- Zend
My Apache VHost is like this:
<VirtualHost *:80>
ServerAdmin webmaster#billingsystem.localhost
DocumentRoot /opt/lampp/htdocs/xampp/billingsystem
ServerName billingsystem
ErrorLog logs/billingsystem.localhost-error.log
CustomLog logs/billingsystem.localhost-access.log common
<directory /opt/lampp/htdocs/xampp/billingsystem>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
My .htaccess in public folder is like this:
RewriteEngine on
# The leading %{DOCUMENT_ROOT} is necessary when used in VirtualHost context
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
If I browse to http://billingsystem, it shows the apache directory path on the browser. If I go to http://billingsystem/public, the application executes code on the web page. Is it possible to create or modify .htaccess file such that, when a user browses to http://billingsystem, it should redirect the browser to http://billingsystem/public and execute the code instead of showing the directory structure?
Also, how can I redirect the user to "public" directory when he tries to access any folder through the browser?
I just went through something like this on a site. My solution was that I needed to use two .htaccess files on the domain. One in the root level of the site and another in the public folder.
So, the one at the root of the domain looks like this:
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options +FollowSymLinks
RewriteEngine On
#Zend Rewrite Rules
RewriteRule ^(.*)$ /public/$1 [NC,L]
AddHandler php5-script .php
Within the public folder I have the following rules in place:
<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ index.php [NC,L]
This seems to work well to get all content trafficking through the Zend framework.
Hope this is helpful.
- liam
To directly answer your question you can place a .htaccess directly in the billingsystem folder with a rewrite rule:
RewriteRule ^(.*)$ /public/$1 [NC,L]
However, your setup should look more like the following:
File System
billingsystem
-application
-design
-public
--index.php
--.htaccess
-library
-- Zend
Virtual Host
<VirtualHost *:80>
ServerAdmin webmaster#billingsystem.localhost
DocumentRoot /opt/lampp/htdocs/xampp/billingsystem/public
ServerName billingsystem
ErrorLog logs/billingsystem.localhost-error.log
CustomLog logs/billingsystem.localhost-access.log common
<directory /opt/lampp/htdocs/xampp/billingsystem/public>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Now the question that remains is that i know you have stuff in you design directory that aparently needs to be web accessible... Can you elaborate on the directory structure in design so that we can figure out what you need to do (if anything) to properly access the various types of files contained in it?

404 error for mod_rewrite using SSL and MAMP

I am building an app in Zend Framework at the moment and testing it all locally. I have Mamp Pro as my web server and I have a self-signed SSL which all seems to work. My problem comes when I try to do mod_rewrite - I just get 404 pages.
The way I have things set up (which may not be the best way...)
In Mamp I have 2 virtualhosts set up both pointing to the same web directory (webroot/public/):
secure.myapp.com
myapp.com
In my public directory is my index.php file and my .htaccess file. The contents of the .htaccess file are:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
When I visit http://myapp.com everything routes as it should using the mod_rewrite. But when I go to https://secure.myapp.com the index page is fine, but URL routing stops working and it appears to be that the .htaccess file is being ignored.
In my ssl.conf I have the following:
<IfModule mod_ssl.c>
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout 300
SSLMutex file:/Applications/MAMP/logs/ssl_mutex
<VirtualHost _default_:443>
SSLEngine on
DocumentRoot "/webroot/public"
ServerName secure.myapp.com
ServerAdmin you#example.com
ErrorLog /Applications/MAMP/logs/ssl_error_log
TransferLog /Applications/MAMP/logs/ssl_access_log
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key
CustomLog /Applications/MAMP/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfModule>
Does anybody have any ideas on this? I'll be sooooo appreciative of the help as it's seriously hindering my development!
Well I'm pretty sure that I have got this working. Basically, a big problem I had is that Mamp does not store vhosts.conf as an accessible file. Instead this is an aliased application file.
I think what happens is that the virtualhosts are all dynamically created all on the standard http port, in my case 80. However I needed to be able to access the port 433 vhost config to enable FileInfo. So my workaround is to ditch my .htaccess file and stick the following ALL into my ssl.conf file.
<IfModule mod_ssl.c>
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout 300
SSLMutex file:/Applications/MAMP/logs/ssl_mutex
<VirtualHost mysite.com:443>
SSLEngine on
DocumentRoot /webroot/secure
ServerName mysite.com
ServerAdmin you#example.com
ErrorLog /Applications/MAMP/logs/ssl_error_log
TransferLog /Applications/MAMP/logs/ssl_access_log
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key
CustomLog /Applications/MAMP/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
RewriteLog /Applications/MAMP/logs/ssl_rewrite_log
RewriteLogLevel 3
</IfModule>
</VirtualHost>
</IfModule>
I had to add DOCUMENT_ROOT in front of my file and directory checks, and a forward slash in front of index.php. If I could have put this into a "Directory" then I think I could have avoided these changes, but Apache won't restart when I add this parameter.
The only thing I didn't try was adding the info to MAMP's httpd.conf, but I have a feeling the same restrictions may be in place.