Correct usage of Rewriterule using a specific domain - html

im trying to build a redirect using .htaccess .
I have to domains, a german one called "german.de" and an english one called "english.com"
Now I want to forward some links to certain youtube videos. To be more specific I want the same links on both domains , e.g.:
german.de/catvideo
english.com/catvideo
for the german one I have working rules like:
Redirect 302 /catvideo http://youtube.com/watch?catsarecoolADDAD
for the english one i tried to add
RewriteCond %{HTTP_HOST} ^(www\.)?english\.com
RewriteRule "^/catvideo$" "https://www.youtube.com/watch?catsarecoolADDAD" [R=301,L]
But it does not seem to work, if I change it to :
RewriteRule "^$" "https://www.youtube.com/watch?catsarecoolADDAD" [R=301,L]
it correctly redirects "english.com" to the above youtube link. Please help me.

Remove the slash
RewriteRule "^catvideo$" "https://www.youtube.com/watch?catsarecoolADDAD" [R=301,L]

Question is solved, I did the redirects on the apache2 webserver, /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName german.de
ServerAdmin webmaster#localhost
DocumentRoot /var/www/
Redirect /catvideo https://www.youtube.com/watch?catsarecoolADDAD
</VirtualHost>
<VirtualHost *:80>
ServerName english.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/
Redirect /catvideo https://www.youtube.com/watch?catsarecool1234
</VirtualHost>

Related

How to use SSL HTML and Websockets on Apache?

I have only used Apache HTML on my backend and implemented my app using HTML/PHP requests so far. Now I want to implement a socket connection. For this, I am currently trying to set up the socket module on my Apache web server. I tried these steps. Reverse Proxy. However, after adding ProxyPass on the VirtualHost :443, I can no longer access my HTML pages.
503 Service Unavailable - The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Is it possible to still access the HTML/PHP pages despite the socket module? Do i have to create a new VirtualHost with a different Port, e.g. the Websocket Port but how can i make the handshake?
My apache2/sites-available/conf looks like this:
<VirtualHost *:80>
ServerName ***
<IfModule mod_ssl.c>
Redirect / https://***
</IfModule>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/***
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName ***
ServerAdmin webmaster#localhost
DocumentRoot /var/www/***
<Directory /var/www>
# Options -Indexes +FollowSymLinks
# AllowOverride none
# Order allow,deny
# allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond ${HTTP:Upgrade} websocket [NC]
RewriteCond ${HTTP:Connection} upgrade [NC]
RewriteRule .* "wss:/localhost:12123/$1" [P,L]
ProxyPass / https://localhost:12123/ #Here is the problem
ProxyPassReverse / https://localhost:12123/
ProxyRequests off
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/***/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/***/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/***/chain.pem
</VirtualHost>
</IfModule>

VirtualHost redirect loop after applying SSL from COMODO

After I applied the configuration it loops until I get an "ERR_TOO_MANY_REDIRECTS"
This is my VirtualHost configuration:
NameVirtualHost *
<VirtualHost *:80>
ServerName my-domain.com
ServerAlias my-site.my-domain.com
DocumentRoot /var/www/my-site
ErrorLog /home/my-site/logs/my-site/error.log
CustomLog /home/my-site/logs/my-site/access.log combined
Redirect permanent / https://my-site.my-domain.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin#my-domain.com
ServerName my-domain.com
ServerAlias my-site.my-domain.com
DirectoryIndex index.php
DocumentRoot /var/www/my-site
ErrorLog /home/my-site/logs/my-site/ssl/error.log
CustomLog /home/my-site/logs/my-site/ssl/access.log combined
SSLEngine on
SSLCertificateFile /home/my-site/SSL/site_com_ar.crt
SSLCertificateKeyFile /home/my-site/SSL/HSSL-5dceb81ff3d10.key
SSLCertificateChainFile /home/my-site/SSL/USERTrustRSAAddTrustCA.crt
</VirtualHost>
How can I track down this issue?
I've solved it just in case anyone needs it:
i've added or modified a ".htaccess" file in each subdomain's root directory with the following:
First be sure you've got "mod_rewrite" enabled:
sudo a2enmod rewrite
Then reset apache:
sudo systemctl restart apache2
Now create or modify (in case it already exists) ".htaccess" in your subdomain root directory:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
</IfModule>
Hope this helps you too!

Apache Virtual Host redirect to document root directory

I have successfully set the DocumentRoot for a given server names:
<VirtualHost *:80>
DocumentRoot "/var/www/html/domain1"
ServerName www.domain1.com
ServerAlias *.domain1.com
#Other directives here
</VirtualHost>
I can't seem to figure out, how to move the subfolders ie."www.domain1.com/contact-us" so it presents index.html located in "/var/www/html/domain1".
I tried adding the alias for the /contact-us in the VirtualHost instructions:
<VirtualHost *:80>
DocumentRoot "/var/www/html/domain1"
ServerName www.domain1.com
ServerAlias *.domain1.com
#Other directives here
Alias /contact-us /var/www/html/domain1
</VirtualHost>
It doesn't work as expected.
I am thinking doing this via .htaccess in the subfolder for the domain1. How would I go around redirecting everything after the domain name to the index.html?
RewriteEngine on
RewriteRule ^subdirectory/(.*)$ /$1 [R=301,NC,L]
RewriteRule ^about-us/(.*)$ /$1 [R=301,NC,L]
RewriteRule ^contact/(.*)$ /$1 [R=301,NC,L]
RewriteRule ^subfolder/(.*)$ /$1 [R=301,NC,L]
Test out this code, make sure the change the folder names.
EDIT
This must be in your .htaccess in your web directory root folder.

Capital letters URL with cPanel?

my website have this link, but when I change hello to HELLO, page is not found
www.mywebsite.com/hello
I've searched a lot of question about capital letters URL. The answer is basically the same, which is setting the .htaccess and setting the RewriteMap httpd.conf. My website is using cPanel 62.0.15 and I don't think that I can access httpd.conf. I didn't found that file anywhere.
Is there any other way to get capital letters URL working? Or where can I find the httpd.conf file in cPanel?
My .htaccess
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteBase /
RewriteRule ^(.*)$ index.php?xparam=$1 [QSA,L]
</IfModule>
If you add NC as a RewriteRule then this makes the match case insensitive:
RewriteRule ^(.*)$ index.php?xparam=$1 [QSA,L]
Becomes ..
RewriteRule ^(.*)$ index.php?xparam=$1 [QSA,L,NC]
See https://httpd.apache.org/docs/current/rewrite/flags.html for more

rewrite localhost to www directory

I had a lot of difficulties getting a domain of mine to point to a folder in my Wamp /www directory.
However, I'm now wanting to work on getting another domain working, but before that I'd like to work on the domain under localhost and edit it through there.
But, whenever I go to localhost or the Ip of the server on a browser, it goes to my domain.
I only want to go to that domain when I type the domains name, not when I type localhost on that machine or the IP on a different machine.
TL:Dr;
I want mywebsite.com > /www/mywebsite (this has already been done)
I want localhost/ > /www (main folder)
Windows Server with WAMP
Here's my current htaccess to get the domain working with the folder (probably not an efficient way) Removed thanks to RiggsFolly
RewriteEngine On
RewriteCond %{HTTP_HOST} (?:www\.)?mywebsite\.com [NC]
RewriteCond %{REQUEST_URI} !^/mywebsite
RewriteRule ^(.*)$ /mywebsite/$1 [L]
RewriteRule ^(.*)$ http://mywebsite.comk/$1 [L,R=301]
After adding Virtual hosts
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info#mywebsite.com
DocumentRoot "c:/wamp/www/mywebsite"
ServerName mywebsite.com
ServerAlias www.mywebsite.com
ErrorLog "logs/mywebsite-error.log"
CustomLog "logs/mywebsite-access.log" common
</VirtualHost>
Still not working.
localhost will load mywebsite.com (name changed for privacy). I want localhost to load the main directory not the mywebsite sub-directory!