I have rules for forcing www and suppressing php extensions. How can I consolidate them into one rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L
You cannot combine them into 1 rules since one rule is external redirect and 2nd in doing rewrite internal only.
But you can correct the 2nd rule a bit:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Related
I have the following rules to redirect all request to https://www.mainsite.com
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Now I want to redirect http://another-domain.com to a specific folder (blog) but without https so I added this. but
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?another-domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1
RewriteCond %{HTTP_HOST} ^(www.)?another-domain$ [NC]
RewriteRule ^(/)?$ blog/index.php [L]
Even with that http://another-domain.com is still redirected to https://www.mainsite.com
Have it this way:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?!(www\.)?another-domain\.com$)(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=302,L,NE]
RewriteCond %{HTTP_HOST} ^(www\.)?another-domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!blog/).+)$ blog/$1 [L]
RewriteCond %{HTTP_HOST} ^(www\.)?another-domain\.com$ [NC]
RewriteRule ^/?$ blog/index.php [L]
How do I write an exclude rule so that my urls can still use http?
I want to have an exclude rule for index.php?route=ebay/openbay/* but are not sure how to do this?
I have tried the following:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/index\.php?route=ebay/openbay/*
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !^/index\.php?route=ebay/openbay/*
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Thank you
You can use:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{THE_REQUEST} !\s/index\.php\?route=ebay/openbay/*
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{THE_REQUEST} !\s/index\.php\?route=ebay/openbay/
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^sitemap\.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase\.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
I have the following lines written multiple times to accommodate the multiple domains we use. Would there be a way to write this once so any domain would follow the same rule?
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/+example.com/(\S*) [NC]
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/example.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example.com/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example.com/index.php [L]
Try this single block of rule for all the doamins:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteCond %1::%{THE_REQUEST} ^(.+?)::\s/+\1/(\S*)
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{HTTP_HOST}::%{REQUEST_URI} ^(?:www\.)?(.+?)::/(?!\1/) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ %1/$1 [L]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^/?$ %1/index.php [L]
The below code disables subdomains, but I can't figure out how to add an exception for a specific subdomain.
I searched for questions on this subject and could not find anything.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Subdomain Exceptions...
RewriteCond %{HTTP_HOST} !^widgets\.hyperbot\.tv$
# Disable Subdomains
RewriteCond %{HTTP_HOST} !^www\.hyperbot\.tv$
RewriteRule (.*) http://www.hyperbot.tv/ [R=301,L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png)$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !(www\.)?hyperbot\.tv [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule (.*) - [F,NC,L]
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})
</IfModule>
To disable all subdomains except one you can use:
RewriteCond %{HTTP_HOST} (^|\.)hyperbot\.tv$ [NC]
RewriteCond %{HTTP_HOST} !^(www|widgets)\.hyperbot\.tv$ [NC]
RewriteRule ^ http://www.hyperbot.tv%{REQUEST_URI} [NE,R=301,L]
try this code
RewriteCond %{HTTP_HOST} !^(www\.)?mysite\.tld$ [NC]
RewriteRule ^ - [F,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Having some trouble with .htaccess and conflicting rules.
Code below:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Options +FollowSymLinks
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
DirectoryIndex index.php
RewriteRule ^home/?$ index.php [L]
RewriteRule ^([a-zA-Z0-9-]+)?$ static-page.php?slug=$1 [L]
The pages based on static-page.php work fine but when I try going to '/home' the page loads for a while then gives me nothing.
I believe this is because the second rule is overwriting the first one.
Anyone know how to solve this?
Thanks,
Try this corrected code:
DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^home/?$ index.php [L]
RewriteRule ^([a-zA-Z0-9-]+)?$ static-page.php?slug=$1 [L,QSA]