I'm trying to force HTTPS through .htaccess and I'm constantly getting an error of too many redirects.
This is my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^patrickwhitehouse.pw$ [NC]
RewriteRule ^(.*)$ http://patrickwhitehouse.pw/$1 [L,R=301]
#force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Options +MultiViews
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^&\ ]+).html
RewriteRule .* /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.html [L]
RedirectMatch ^/blogs$ http://www.patrickwhitehouse.pw/blog.html
Your first rewrite rule is the culprit, for each successful redirection to https it then re-redirects to the hard coded http again on the next request after the external redirection...
Try this slightly modified version instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^patrickwhitehouse.pw$ [NC]
RewriteRule ^(.*)$ %{REQUEST_SCHEME}://patrickwhitehouse.pw/$1 [L,R=301]
#force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Or, a bit cleaned up:
RewriteEngine On
# force host 'patrickwhitehouse.pw'
RewriteCond %{HTTP_HOST} !^patrickwhitehouse.pw$ [NC]
RewriteRule ^ %{REQUEST_SCHEME}://patrickwhitehouse.pw%{REQUEST_URI} [L,R=301]
# force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Related
I have .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule cache/ - [F]
Options -Indexes
RewriteCond %{HTTP_HOST} ^www.domains.eu [NC]
RewriteRule ^(.*)$ https://domains.eu/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9\-\_\/]*)$ index.php?p=$1
# Blokada hotlinking czyli kradzieży obrazków
RewriteCond %{HTTP_REFERER} !^https://(.+\.)?domains.pl/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
#RewriteRule .*\.(jpe?g|jpg|gif|bmp|png|jpeg)$ - [F]
#AuthType Basic
#AuthName "Password Protected Area"
#AuthUserFile /home/webplay/domains/domains.eu/public_html/.htpasswd
#Require valid-user
# Prevent viewing of htaccess file.
<Files .htaccess>
order allow,deny
deny from all
</Files>
RedirectMatch 403 ^.*/apps/(.*).php(.*)$
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl|map)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
I need the following redirection::
redirect from http ://domains .pl, http ://www.domains .pl, https ://www.domains .pl, https ://domains .pl to https ://domains .eu
redirect from https ://www.domains .eu, http ://www.domains .pl, http ://domains .eu, to https ://domains .eu
Could I ask for help from my .htaccess made into these redirects?
will you please add below code and test it?
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://domains.eu/$1 [L,R=301]
Whit this code, the 404 redirect doesnt work. I dont get any error. If i type in an url that doesnt exists, i only get an empty white page.
Code updated:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ htaccess.php?q=$1 [QSA]
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
#RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
#RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteBase /
ErrorDocument 404 404.php/
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ 404.php [L]
Change ErrorDocument 404 /index.php to
RewriteEngine On
RewriteBase /
ErrorDocument 404 http://yourdomain.com/404.php/
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /path/to/404.php [L]
The Rewrite rules map that URL to your 404.php script.
See this link for more information: http://httpd.apache.org/docs/current/mod/core.html#errordocument
I have my site running on all over SSL, but I added a games sections which uses the 3rd party games in flash. When I enable SSL it stop working. I am wondersing if how can I only disable the SSL on that specific page which contains "/game/" in the url so that the games will work fine.
I tried this code from insternet in my .htaccess file but not working:
RewriteCond %{HTTPS} off
RewriteRule ^game^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
EDIT:
I tried the answer suggested:
RewriteEngine On
RewriteCond %{HTTPS} On [NC]
RewriteRule ^game http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
It works but when I go the pages contained the word "game" it turns the other pages also to "http" and other pages are become using "http" instead of "https"
Then I tried this:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} On [NC]
RewriteRule ^game http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
This it starts giving me the message "Page is not redirecting properly" when I go to "game" page url.
I want only the "game" pages to use "http".
EDIT TWO: The FULL .htaccess file
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On
# #todo This may not be effective in some cases
FileETag Size
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>
Need help. Let me know if any duplicate is found, I can not find anyone though.
Thanks.
This should be your full .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# except for /game/ enforce https
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/game/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# for /game/ enforce http
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /game/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} public [OR]
RewriteCond %{REQUEST_URI} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
Make sure to clear your browser cache before testing this change.
Why each page redirects to domain? I move dkcherta.ru -> dkchertanovo.ru and want for example http://dkcherta.ru/index.php?id=80 -> http://dkchertanovo.ru/index.php?id=80
My .htaccess:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?dkcherta\.ru$ [NC]
RewriteRule ^ http://dkchertanovo.ru/%{REQUEST_URI} [L,R=301]
RewriteRule ^rss_afisha[/]?$ /index.php?id=230 [L]
RewriteRule ^rss_news[/]?$ /index.php?id=231 [L]
ErrorDocument 404 http://dkchertanovo.ru/
# For full documentation and other suggested options, please see
# http://svn.modxcms.com/docs/display/MODx096/Friendly+URL+Solutions
# including for unexpected logouts in multi-server/cloud environments
RewriteBase /
# Сливка доменного имени
#RewriteCond %{HTTP_HOST} ^dkchertanovo\.ru$ [NC]
#RewriteRule ^(.*)$ http://www.dkchertanovo.ru/$1 [R=301,L]
RemoveHandler .php .htm .html
AddType application/x-httpd-php .php .htm .html
AddHandler application/x-httpd-php .php .htm .html
php_flag register_globals off
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
# Exclude /assets and /manager directories from rewrite rules
RewriteRule ^(manager|assets) - [L]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
### force www
#RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#RewriteBase /
# Reduce server overhead by enabling output compression if supported.
#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5
You don't need multiple lines of these:
Options +FollowSymLinks -MultiViews
RewriteEngine On
Just put only once at the top and it should be effective for rest of the file.
Then to solve your problem move this rule on top of all other rules in your .htaccess file:
RewriteCond %{HTTP_HOST} ^(www\.)?dkcherta\.ru$ [NC]
RewriteRule ^ http://dkchertanovo.ru%{REQUEST_URI} [L,R=301]
Am rather new to this world of htaccess redirects.Am trying to force all redirects in my Zend MVC to my https but I get a requested URL not found error on requests that dont go though the index controller
Example
https://www.example.com/auth/register
gives a requested URL /auth/register not found error. However if I remove the https redirect rule it works fine over http. If I adjust the URL to
https://www.example.com/index.php/auth/register
it works fine.
The URL
https://www.example.com/index/faq
works just fine since it goes through the index controller.
My .htaccess file looks like this
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
What do I need to adjust to get the URL
https://www.example.com/auth/register
working?
Your code reads as "If this matches a file, link, or directory, then do nothing and continue." You need to skip the final rewrite rule in the case the file actually exists:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=1,NC,L]
RewriteRule ^.*$ index.php [NC,L]