Author |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Wed 08 Aug '18 17:31 Post subject: Rewrite rule |
|
|
Hello
I have a website running in apache.
Now I need one page with https and all other pages should run with http only
I tried with more than 20 rules, but nothing works
Please help |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 09 Aug '18 8:44 Post subject: Re: Rewrite rule |
|
|
manues50 wrote: |
I tried with more than 20 rules, but nothing works
|
Rules?
You have to setup virtual / hosts for each domain / page. You can define one with SSL on port 443 and the others on port 80. |
|
Back to top |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Thu 09 Aug '18 11:06 Post subject: Re: Rewrite rule |
|
|
I already created a virtual host for both.
Here is the sample I used, it will do https except for room.php, but I need just the opposite of this.
RewriteEngine On
# Go to https if not on room.php
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/room.php$ [NC]
RewriteRule ^(.*)$ https://www.mycookiedomain.com/$1 [R,L]
# Go to http if you are on room.php
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/room.php$ [NC]
RewriteRule ^(.*)$ http://www.mycookiedomain.com/$1 [R,L] |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Fri 10 Aug '18 10:50 Post subject: |
|
|
The fist condition better be
RewriteCond %{HTTPS} !=on
so the complete code
Code: |
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/room\.php$ [NC]
RewriteRule ^ https://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
|
|
|
Back to top |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Fri 10 Aug '18 16:41 Post subject: |
|
|
Thank you for the update
It is work for me partially. When I click the page'room.php' the website moves to https.
Now the problem is once the website redirects to https it not return to http for other pages
Please alter the rule like this " when I click on room.php it should redirect to https, when I click any other page the https redirect to http" |
|
Back to top |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Mon 13 Aug '18 15:07 Post subject: |
|
|
Can someone help me to complete this task? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Tue 14 Aug '18 16:55 Post subject: |
|
|
Code: |
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/room\.php$ [NC]
RewriteRule ^ https://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/room\.php(.*)$
RewriteRule ^ http://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
|
|
|
Back to top |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Tue 14 Aug '18 19:52 Post subject: |
|
|
Thank you for the update.
I have still issue with fetching css files and images, Please see the below logs from the browser inspect.
10Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure stylesheet '<URL>'. This request has been blocked; the content must be served over HTTPS.
13Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure script '<URL>'. This request has been blocked; the content must be served over HTTPS.
payment.php:1 Mixed Content: The page at 'https://www.mycookiedomain.com/room.php' was loaded over HTTPS, but requested an insecure image 'http://www.mycookiedomain.com/assets/img/usa_flag.png'. This content should also be served over HTTPS.
payment.php:1 Mixed Content: The page at 'https://www.mycookiedomain.com/room.php' was loaded over HTTPS, but requested an insecure image 'http://www.mycookiedomain.com/assets/img/canada_flag.png'. This content should also be served over HTTPS.
payment.php:1 Mixed Content: The page at 'https://www.mycookiedomain.com/room.php' was loaded over HTTPS, but requested an insecure image 'http://www.mycookiedomain.com/assets/img/logo-footer.png'. This content should also be served over HTTPS.
payment.php:1 Mixed Content: The page at 'https://www.mycookiedomain.com/room.php' was loaded over HTTPS, but requested an insecure prefetch resource 'http://www.mycookiedomain.com/assets/data-table/css/jquery.dataTables.css'. This request has been blocked; the content must be served over HTTPS.
payment.php:1 Mixed Content: The page at 'https://www.mycookiedomain.com/room.php' was loaded over HTTPS, but requested an insecure prefetch resource 'http://www.mycookiedomain.com/assets/data-table/css/normalize.css'. This request has been blocked; the content must be served over HTTPS.
payment.php:257 Uncaught ReferenceError: $ is not defined
at payment.php:257
(anonymous) @ payment.php:257
payment.php:305 Uncaught ReferenceError: $ is not defined
at payment.php:305
(anonymous) @ payment.php:305
payment.php:1 Mixed Content: The page at 'https://www.mycookiedomain.com/room.php' was loaded over HTTPS, but requested an insecure favicon 'http://www.mycookiedomain.com/assets/img/icons/favicon.png'. This request has been blocked; the content must be served over HTTPS. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 15 Aug '18 8:46 Post subject: |
|
|
don't use http:// in the paths nor the domainname of your images and other resources, but absolutes path like /assets/img/usa_flag.png
Last edited by James Blond on Wed 15 Aug '18 12:59; edited 1 time in total |
|
Back to top |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Wed 15 Aug '18 12:33 Post subject: |
|
|
James Blond wrote: | don't use http:// in the paths nopr the domainname of your images and other resources, but absolutes path like /assets/img/usa_flag.png |
Hello James,
I already gave the path like this
<link rel="stylesheet" type="text/css" href="vendor/font-awesome/4.6.32/css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="assets/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/flexible-bootstrap-carousel.css">
<link rel="stylesheet" type="text/css" href="assets/css/legacy.css">
<link rel="stylesheet" type="text/css" href="assets/css/application.css">
I think the following error shows its issue from server,
"Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure stylesheet '<URL>'. This request has been blocked; the content must be served over HTTPS."
This issue comes after the I enabled the second rule |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 15 Aug '18 13:03 Post subject: |
|
|
manues50 wrote: |
This issue comes after the I enabled the second rule |
True, since the second rules forces everything that is not room.php as you wanted...
So how do you realy want the rewriting? Force only php files? Directories? |
|
Back to top |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Fri 17 Aug '18 10:37 Post subject: |
|
|
Sorry for the confusion.
I have so many pages on my home page
I need room.php to be https, on that time everything related to this php file also should https(css,png,jpg,etc).
If I click on other pages, then it should redirect to http, as well as their respective subfolders and css,png,jpg, also should be work with http |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Sun 19 Aug '18 15:40 Post subject: |
|
|
I guess this should do the trick. So it jumps only back to http:// if the url contains .php but not room.php
Code: |
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/room\.php$ [NC]
RewriteRule ^ https://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/(.*)\.php(.*)$
RewriteCond %{REQUEST_URI} !^/room\.php(.*)$
RewriteRule ^ http://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
|
|
|
Back to top |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Mon 20 Aug '18 12:47 Post subject: |
|
|
Hello James,
This was helpful.
Thank You |
|
Back to top |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Wed 21 Nov '18 12:36 Post subject: |
|
|
James Blond wrote: | I guess this should do the trick. So it jumps only back to http:// if the url contains .php but not room.php
Code: |
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/room\.php$ [NC]
RewriteRule ^ https://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/(.*)\.php(.*)$
RewriteCond %{REQUEST_URI} !^/room\.php(.*)$
RewriteRule ^ http://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
|
|
Hello James
Your code was helpful to me, I am trying with just opposite of that rule
That is, need to enable https for my website except for one page
I tried with the following but it does not work properly.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/(.*)\.php(.*)$
RewriteCond %{REQUEST_URI} !^/live\.php(.*)$
RewriteRule ^ https://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/live\.php$ [NC]
RewriteRule ^ http://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
here live.php contains stream URLs so I need that should be with http and all other with https.
like if I click on live.php its should be http and if I click on some other page it should be with https. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 21 Nov '18 18:56 Post subject: |
|
|
The second part is correct.
Code: | RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/live\.php$ [NC]
RewriteRule ^ https://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/live\.php(.*)$
RewriteRule ^ http://www.mycookiedomain.com%{REQUEST_URI} [L,R=301] |
But why for streaming http? https is much faster in transport, especially if you use mod_h2 for http/2 |
|
Back to top |
|
manues50
Joined: 07 Aug 2018 Posts: 15 Location: India
|
Posted: Thu 22 Nov '18 10:54 Post subject: |
|
|
Hello James,
Thank you for the update.
I have tried with the below code and is working
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/live\.php$ [NC]
RewriteRule ^ https://www.mycookiedomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/live\.php(.*)$
RewriteRule ^ http://www.mycookiedomain.com%{REQUEST_URI} [L,R=301] |
|
Back to top |
|