How can I Implement HTTPS for all pages Yii2 - yii2

I want all pages of my website(website and restfull api) to be accessed via https. Following this post(Yii 1.1: URL management for Websites with secure and nonsecure pages), I understand that it is for a website that will have nonsecure and secure pages.
should I do it as explained the post or there is a specific way for website for which everything uses https?

You might need something like this in your .htaccess file
RewriteEngine on
RewriteBase /frontend/web/
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

Related

Redirect From Pretty URL to .html URL

I have recently switched from using Wordpress to a static html only site. When I remade each page (there are only 6 pages total) I kept the same URL name.
Example: https://reactiongaming.us/alteriwnet/ is now https://reactiongaming.us/alteriwnet.html
My issues is that old links and Google search results contain the reactiongaming.us/alteriwnet/ version which results in a 404 error. I have tried various .htaccess methods for "pretty URLs but none worked. Usually, these questions were asked on how to redirect from a .html URL to a pretty URL, but I'm trying to do the opposite.
There are only 6 URLs I need to redirect in total from reactiongaming.us/example/ to reactiongaming.us/example.html. Is there an .htaccess or other method to achieve this?
I have tried:
RewriteCond %{THE_REQUEST} \.html [NC]
RewriteRule ^(.*)\.html$ /$1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
You can use Redirect directive to redirect your old URLs to the new URL format
Redirect 301 /alteriwnet/ /alteriwnet.html
This will 301 redirect /alteriwnet to /alteriwnet.html .
To redirect multiple URLs with just a one liner code you can use RedirectMatch which uses a regex based pattern
RedirectMatch 301 ^/(alteriwnet|path2|path3)/?$ /$1.html
References :
Redirect directive
https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect
RedirectMatch directive
https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirectMatch

htaccess why is site redirecting to //

In my htaccess I am redirecting all non https to https.
It works, but its also adding in an extra '/', so the url is
'https: //www.[MY SITE URL].co.uk//'
Why is this? To be honest, I don't really know what all this in my htaccess is doing, its copied from googling answers to 'redirect all requests to https'
My htaccess:
Options -MultiViews
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
#RewriteCond %{HTTP_HOST} ^(www\.)?jobooz\.com [NC]
#RewriteRule ^(.*)$ https://www.jobooz.co.uk/$1 [R=301,L,NC]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/$1
RewriteRule ^/?$ /php/index.php [NC,L] # Home page
I've also noticed any deeper urls like '/search-jobs/jobs-near-me' that I add to the url then get duplicated too, to '/search-jobs/jobs-near-me/search-jobs/jobs-near-me' when redirected to https.
All urls work fine if I go directly to the https version.
Any help appreciated, thanks.
The following rewrite rule has a problem:
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
The gist of why you are seeing repeated fragments in the rewritten URL is that (.*) matches everything, and that already includes the host and URI. Instead, you can try redirecting any incoming request on port 80 to HTTPS.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

modrewrite to remove the file extension but still load the page

I have a subdomain with .php pages in it. I just want to remove the .php I have written some code gathered from other posts on stack, so far I have this
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} (\.php(.*)\sHTTP/1)
RewriteRule ^(.+)\.php$ /$1 [R=301,L,QSA]
this rewrites
subdomain.example.com/weddings.php
to
subdomain.example.com/weddings
However it also creates a 404 page not found error. Am I doing something wrong?
Solved it. anyone struggling with the same thing here is my solution
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
found it on
http://css-tricks.com/snippets/htaccess/remove-file-extention-from-urls/
a fantastic website.

difference between www.xyz.com and xyz.com and how to redirect .htaccess

I have a site and am using Google Webmaster tool. I created the setting within the tool for the site twice: once as www.xyz.com and once as xyz.com. The statistics from both are different once I drill down into details.
I want to stick with www.xyz.com. How can I make everyone go to xyz.com be redirected to www.xyz.com? and will this harm my ranking or indexing in google?
regards,
sorry if the question is simple :)
with htaccess, i use the following for forced www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]
although you might be best doing the following if if it is for SEO purposes
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.htm
RewriteRule ^(.*)index.htm$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/home.htm
RewriteRule ^(.*)home.htm$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/home.html
RewriteRule ^(.*)home.html$ http://%{HTTP_HOST}/$1 [R=301,L]
as this also removes any index or home page part of the url.
in webmaster tools in settings, you can also select always use www, which will merge the data for both domains under a single www domain (although you will be able to see both www and non-www listed in GWMT)
Use preffered domain, more instructions here:
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=44231
Specify a preferred domain:
On the Webmaster Tools Home page, click the site you want.
Under Site configuration, click Settings.
In the Preferred domain section, select the option you want.
You could also use 301 redirect:
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=93633

.htaccess redirect

Just wondering if someone can help me with the following issue.
I want to redirect my site to a subdomain, whishc simply displays a maintenace page, allowing me to work on the main site.
So I have the following code for my .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.co.uk$
RewriteRule ^/?$ "http\:\/\/maintenance\.domain\.co\.uk" [R=301,L]
However, I need to access the root domain to be able to view the work that I have done; however, I only want myself on my IP to be able to view that and the outside world is redirected to the subdomain which displays the maintenace page.
I would have thought that the following code:
RewriteCond %{REMOTE_HOST} !^00\.000\.00\.000
Would have allowed me to do that; however, I'm still being redirected to the sub domain and I wondered is someone could assist me further wth this.
Thanks
You'd be better of using %{REMOTE_ADDR}, I believe:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [NC]
RewriteCond %{REMOTE_ADDR} !=00.00.00.00
RewriteRule ^/?$ http://maintenance.domain.co.uk/ [R=301,L]