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

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?

Related

Redirect from HTTPS to HTTPS of other website

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>

Website needs to convert from http to https redirect

I am working on a website and I have secured it using an SSL Certificate. The Https: works when manually typed in https://www.example-direct.co.uk it shows no error and has a secure icon. However, if we enter example.co.uk it directs it to the http: without the secure key.
I am just wondering if I can do a simple redirect? This is the redirect we currently have set up in .htaccess. What do I add here to redirect to http: to Https://
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# Redirect non www. to www.
RewriteCond %{HTTP_HOST} !^www\.example-direct\.co\.uk
RewriteRule (.*) http://www.example-direct.co.uk/$1 [R=301,L]
# Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1? [R=301,L]
# Remove .php ONLY if requested directly
RewriteCond %{THE_REQUEST} (\.php)
RewriteRule ^(.+)\.php /$1 [R=301,L,QSA]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php

Strange issue wordpress facebooks links and portable devices

I have an strange issue, maybe somebody could help me. When I shared link's of my site (wordpress) vía facebook, everything is ok in PC, but in IPAD or cellullar, when I click in facebook link I get 403 forbidden error.
UPDATED: I think maybe error could be in .htaccess is blocking traffic from l.facebook.com/l.php
# BEGIN All In One WP Security
#AIOWPS_BLOCK_WP_FILE_ACCESS_START
<Files license.txt>
order allow,deny
deny from all
</files>
<Files wp-config-sample.php>
order allow,deny
deny from all
</Files>
<Files readme.html>
order allow,deny
deny from all
</Files>
#AIOWPS_BLOCK_WP_FILE_ACCESS_END
#AIOWPS_BASIC_HTACCESS_RULES_START
<Files .htaccess>
order allow,deny
deny from all
</Files>
ServerSignature Off
LimitRequestBody 10240000
<Files wp-config.php>
order allow,deny
deny from all
</Files>
#AIOWPS_BASIC_HTACCESS_RULES_END
#AIOWPS_DISABLE_INDEX_VIEWS_START
Options -Indexes
#AIOWPS_DISABLE_INDEX_VIEWS_END
#AIOWPS_DISABLE_TRACE_TRACK_START
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
#AIOWPS_DISABLE_TRACE_TRACK_END
#AIOWPS_FORBID_PROXY_COMMENTS_START
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
#AIOWPS_FORBID_PROXY_COMMENTS_END
#AIOWPS_DENY_BAD_QUERY_STRINGS_START
RewriteCond %{QUERY_STRING} tag= [NC,OR]
RewriteCond %{QUERY_STRING} ftp: [NC,OR]
RewriteCond %{QUERY_STRING} http: [NC,OR]
RewriteCond %{QUERY_STRING} https: [NC,OR]
RewriteCond %{QUERY_STRING} mosConfig [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(globals|encode|localhost|loopback).* [NC,OR]
RewriteCond %{QUERY_STRING} (\;|'|\"|%22).*(request|insert|union|declare|drop) [NC]
RewriteRule ^(.*)$ - [F,L]
#AIOWPS_DENY_BAD_QUERY_STRINGS_END
#AIOWPS_FIVE_G_BLACKLIST_START
# 5G BLACKLIST/FIREWALL (2013)
# # http://perishablepress.com/5g-blacklist-2013/
# 5G:[QUERY STRINGS]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (\"|%22).*(<|>|%3) [NC,OR]
RewriteCond %{QUERY_STRING} (javascript:).*(\;) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3) [NC,OR]
RewriteCond %{QUERY_STRING} (\\|\.\./|`|='$|=%27$) [NC,OR]
RewriteCond %{QUERY_STRING} (\;|'|\"|%22).*(union|select|insert|drop|update|md5|benchmark|or|and|if) [NC,OR]
RewriteCond %{QUERY_STRING} (base64_encode|localhost|mosconfig) [NC,OR]
RewriteCond %{QUERY_STRING} (boot\.ini|echo.*kae|etc/passwd) [NC,OR]
RewriteCond %{QUERY_STRING} (GLOBALS|REQUEST)(=|\[|%) [NC]
RewriteRule .* - [F]
</IfModule>
# 5G:[USER AGENTS]
<IfModule mod_setenvif.c>
# SetEnvIfNoCase User-Agent ^$ keep_out
SetEnvIfNoCase User-Agent (binlar|casper|cmsworldmap|comodo|diavol|dotbot|feedfinder|flicky|ia_archiver|jakarta|kmccrew|nutch|planetwork|purebot|pycurl|skygrid|sucker|turnit|vikspider|zmeu) keep_out
<limit GET POST PUT>
Order Allow,Deny
Allow from all
Deny from env=keep_out
</limit>
</IfModule>
# 5G:[REQUEST STRINGS]
<IfModule mod_alias.c>
RedirectMatch 403 (https?|ftp|php)\://
RedirectMatch 403 /(https?|ima|ucp)/
RedirectMatch 403 /(Permanent|Better)$
RedirectMatch 403 (\=\\\'|\=\\%27|/\\\'/?|\)\.css\()$
RedirectMatch 403 (\,|\)\+|/\,/|\{0\}|\(/\(|\.\.\.|\+\+\+|\||\\\"\\\")
RedirectMatch 403 \.(cgi|asp|aspx|cfg|dll|exe|jsp|mdb|sql|ini|rar)$
RedirectMatch 403 /(contac|fpw|install|pingserver|register)\.php$
RedirectMatch 403 (base64|crossdomain|localhost|wwwroot|e107\_)
RedirectMatch 403 (eval\(|\_vti\_|\(null\)|echo.*kae|config\.xml)
RedirectMatch 403 \.well\-known/host\-meta
RedirectMatch 403 /function\.array\-rand
RedirectMatch 403 \)\;\$\(this\)\.html\(
RedirectMatch 403 proc/self/environ
RedirectMatch 403 msnbot\.htm\)\.\_
RedirectMatch 403 /ref\.outcontrol
RedirectMatch 403 com\_cropimage
RedirectMatch 403 indonesia\.htm
RedirectMatch 403 \{\$itemURL\}
RedirectMatch 403 function\(\)
RedirectMatch 403 labels\.rdf
RedirectMatch 403 /playing.php
RedirectMatch 403 muieblackcat
</IfModule>
# 5G:[REQUEST METHOD]
<ifModule mod_rewrite.c>
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>
#AIOWPS_FIVE_G_BLACKLIST_END
# END All In One WP Security
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
# block visitors referred from semalt.com
RewriteEngine on
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]
Anybody Knows whats going on?
Thanks in advance
This is a partial answer. I received a question from someone I had not worked for before in that some of their viewers are also receiving the 403 error. I was not able to duplicate their error on any of my devices, but some of company's staff was able to reproduce the error. Specifically, it seems that the error is connected with the type of internet connection. To date, our tests indicate that it may have to do with using hot spots generated with i-devices. Commenting out the whole code block with the RedirectMatch 403 statements fixes the access, but we have not been able to isolate it to one line of code - turning them on and off and testing the site.

URL redirection to subdomain without changing URL in address

I am new to Linux and want to use .htaccess or proxy for the URL redirection leaving URL unchanged with apache2.
Now i want to redirect my main domain http://example.com/test to my subdomain http://test.example.com without changing the URL in address bar.
Kindly help me in giving me some guidelines with .htaccess or proxy or some other..
If you don't want the URL to change you either need a Reverse proxy set-up between the two virtual hosts / domains, or if example.com is just an alias, same IP and served from the same Apache virtual host, you could use an internal rewrite. More info HERE
your can also try this. for more infor go HERE
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^/?(index.\php)?$ /category [L]
This only works for requests for http://domain.com/ or http://domain.com/index.php, and you'd get served the content at http://domain.com/category without changing the URL in the address bar. You can probably even lose the RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] line if you don't need it.
there is also a helpful resource here
RewriteEngine on
RewriteBase /
######## example.com ########
RewriteCond %{HTTP_HOST} ^.*example.com$ [NC]
RewriteCond /www/quux-foo.com/www/root/v1%{REQUEST_URI} -d
RewriteRule ^(.*[^/])$ %{REQUEST_FILENAME}/ [L]
RewriteCond %{HTTP_HOST} ^.*quux-foo.com$ [NC]
RewriteCond %{REQUEST_URI} ^/v1/
RewriteRule ^(.*)$ - [F]
RewriteCond %{HTTP_HOST} ^.*example.com$ [NC]
RewriteCond /www/quux-foo.com/www/root/v1%{REQUEST_URI} -f [OR]
RewriteCond /www/quux-foo.com/www/root/v1%{REQUEST_URI} -d
RewriteRule ^(.*)$ v1/$1 [L]
RewriteCond %{HTTP_HOST} ^.*example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/v1/
RewriteRule ^(.*)$ v1/index.php [L]
######## example.com ########

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]