Htaccess: Difference between revisions
Jump to navigation
Jump to search
(Created page with "==Redirect IP to domain==") |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
==Redirect IP to domain== | ==Redirect IP to domain== | ||
<pre> | |||
Options +FollowSymLinks | |||
RewriteEngine on | |||
RewriteCond %{HTTP_HOST} ^555\.555\.555\.555 | |||
RewriteRule (.*) http://www.example.com/$1 [R=301,L] | |||
</pre> | |||
==Force SSL== | |||
<pre> | |||
RewriteCond %{SERVER_PORT} ^80$ | |||
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] | |||
</pre> | |||
==Redirect Main domain to a sub folder== | |||
<pre> | |||
RewriteEngine on | |||
RewriteCond %{HTTP_HOST} ^(www.)?naturaltilecompany.co.uk$ | |||
RewriteCond %{REQUEST_URI} !^/shop/ | |||
RewriteCond %{REQUEST_FILENAME} !-f | |||
RewriteCond %{REQUEST_FILENAME} !-d | |||
RewriteRule ^(.*)$ /shop/$1 | |||
RewriteCond %{HTTP_HOST} ^(www.)?naturaltilecompany.co.uk$ | |||
RewriteRule ^(/)?$ shop/index.php [L] | |||
</pre> | |||
==Redirect Every Request to index page== | |||
<pre> | |||
# BEGIN Rule | |||
<IfModule mod_rewrite.c> | |||
RewriteEngine On | |||
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |||
RewriteBase / | |||
RewriteRule ^index\.php$ - [L] | |||
RewriteCond %{REQUEST_FILENAME} !-f | |||
RewriteCond %{REQUEST_FILENAME} !-d | |||
RewriteRule . /index.php [L] | |||
</IfModule> | |||
</pre> | |||
==Redirect Single Page to HTTPS== | |||
<pre> | |||
RewriteCond %{HTTPS} off | |||
RewriteCond %{REQUEST_URI} ^/marine-australia/login/ | |||
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] | |||
</pre> | |||
==Redirect Query string to homepage== | |||
<pre> | |||
RewriteCond %{QUERY_STRING} [0-9a-zA-Z_-]+$ | |||
RewriteRule ^(.*)$ https://www.example.com/? [R=301,L] | |||
</pre> | |||
==Redirect all pages to single URL== | |||
<pre> | |||
<IfModule mod_rewrite.c> | |||
RewriteEngine on | |||
RewriteRule ^(.*)$ http://johnmeier.com/ [R=301,L] | |||
</IfModule> | |||
</pre> | |||
==Disable POST Requests== | |||
<pre> | |||
<Limit POST> | |||
order deny,allow | |||
deny from all | |||
allow from 127.0.0.1 | |||
</Limit> | |||
</pre> | |||
==Deny From Single IP== | |||
<pre> | |||
order deny,allow | |||
deny from all | |||
allow from x.x.x.x | |||
</pre> | |||
==PHP Code in HTML== | |||
For Cloudlinux | |||
<pre> | |||
AddHandler application/x-httpd-lsphp .htm .html .shtml | |||
AddHandler application/x-httpd-lsphp .php .htm .html | |||
</pre> | |||
For Easy Apache: | |||
<pre> | |||
AddHandler application/x-httpd-ea-php72 .htm .html .php | |||
</pre> | |||
==Block Bad Bots== | |||
<pre> | |||
SetEnvIfNoCase User-Agent "^Yandex" search_bot | |||
SetEnvIfNoCase User-Agent "^Yahoo" search_bot | |||
SetEnvIfNoCase User-Agent "^igdeSpyder" search_bot | |||
SetEnvIfNoCase User-Agent "^Robot" search_bot | |||
SetEnvIfNoCase User-Agent "^Googlebot" search_bot | |||
SetEnvIfNoCase User-Agent "^msnbot" search_bot | |||
SetEnvIfNoCase User-Agent "^Aport" search_bot | |||
SetEnvIfNoCase User-Agent "^Mail" search_bot | |||
SetEnvIfNoCase User-Agent "^bot" search_bot | |||
SetEnvIfNoCase User-Agent "^spider" search_bot | |||
SetEnvIfNoCase User-Agent "^php" search_bot | |||
SetEnvIfNoCase User-Agent "^Parser" search_bot | |||
<Limit GET POST HEAD> | |||
Order Allow,Deny | |||
Allow from all | |||
Deny from env=search_bot | |||
</Limit> | |||
</pre> | |||
Latest revision as of 10:10, 20 June 2024
Redirect IP to domain
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^555\.555\.555\.555
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Force SSL
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
Redirect Main domain to a sub folder
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?naturaltilecompany.co.uk$
RewriteCond %{REQUEST_URI} !^/shop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /shop/$1
RewriteCond %{HTTP_HOST} ^(www.)?naturaltilecompany.co.uk$
RewriteRule ^(/)?$ shop/index.php [L]
Redirect Every Request to index page
# BEGIN Rule
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Redirect Single Page to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/marine-australia/login/
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Redirect Query string to homepage
RewriteCond %{QUERY_STRING} [0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ https://www.example.com/? [R=301,L]
Redirect all pages to single URL
<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^(.*)$ http://johnmeier.com/ [R=301,L] </IfModule>
Disable POST Requests
<Limit POST> order deny,allow deny from all allow from 127.0.0.1 </Limit>
Deny From Single IP
order deny,allow deny from all allow from x.x.x.x
PHP Code in HTML
For Cloudlinux
AddHandler application/x-httpd-lsphp .htm .html .shtml AddHandler application/x-httpd-lsphp .php .htm .html
For Easy Apache:
AddHandler application/x-httpd-ea-php72 .htm .html .php
Block Bad Bots
SetEnvIfNoCase User-Agent "^Yandex" search_bot SetEnvIfNoCase User-Agent "^Yahoo" search_bot SetEnvIfNoCase User-Agent "^igdeSpyder" search_bot SetEnvIfNoCase User-Agent "^Robot" search_bot SetEnvIfNoCase User-Agent "^Googlebot" search_bot SetEnvIfNoCase User-Agent "^msnbot" search_bot SetEnvIfNoCase User-Agent "^Aport" search_bot SetEnvIfNoCase User-Agent "^Mail" search_bot SetEnvIfNoCase User-Agent "^bot" search_bot SetEnvIfNoCase User-Agent "^spider" search_bot SetEnvIfNoCase User-Agent "^php" search_bot SetEnvIfNoCase User-Agent "^Parser" search_bot <Limit GET POST HEAD> Order Allow,Deny Allow from all Deny from env=search_bot </Limit>