My htaccess
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|uploads|images|ws|vendor|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I have also hidden my index.php
Fails to load: -
https://www.abc.in/abc-xyz-fdg
Works: -
https://www.abc.in/index.php/abc-xyz-fdg
Try this
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
You need to make changes in two files.
config.php file $config['secure_base_url']=" https://www.abc.in/";
And open the url_helper.php file (system/helpers/url_helper.php) and alter the code in https://sajjadhossain.com/2008/10/27/ssl-https-urls-and-codeigniter/
Now, add the following code in Config.php file (system/Core/Config.php) as in https://sajjadhossain.com/2008/10/27/ssl-https-urls-and-codeigniter/
reference
This worked for me.
Step 1
SSL config (which runs with https)
<Directory "/var/www/html">
AllowOverride All
</Directory>
Step 2
The .htaccess file should be like this...
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
Reference link :
HTTPS and Remove index.php on CodeIgniter
Thank you guys who tried to him me
Happy Coding!!
Related
I would like to change "/" to "/folder".
So when user clicks link with this url "/page.php" I want it to be automatically translated by .htaccess to "/folder/page.php".
How can I achieve this?
This simple rule should work for you in site root .htaccess (parent directory of folder):
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/ [NC]
RewriteRule .* folder/$0 [L]
Please use .htaccess file. i think its better for you.
Your Need is:
HTTP://YOUR_DOMAIN.COM/page.php
TO
HTTP://YOUR_DOMAIN.COM/FOLDER/page.php
Step1:
create an .htaccess file on your Server
Filename: .htaccess
just Copy this part and Change the Values.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} YOUR_DOMAIN.COM$ [NC]
RewriteCond %{HTTP_HOST} !FOLDER
RewriteRule ^(.*)$ http://YOUR_DOMAIN.COM/FOLDER/$1 [R=301,L]
Reference-1 |
Reference-2
Try this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [QSA,PT,L]
RewriteRule ^$ /folder/$1 [QSA,PT,L]
RewriteRule ^index.php/(.*) $1 [QSA,R,L]
</IfModule>
I have read many answers on the subject but none is mentionning how to combine :
redirecting all traffic to index.php + redirect all http to httpS
the following works great for redirecting all to index.php :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|css|js|robots\.txt)
RewriteRule ^(.*) index.php/params=$1 [L,QSA]
before I was doing this I was able to force http to https using this :
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I just cannot find a way to mix both, so that It would redirect all traffic to index.php using the same conditions and force https.
* edit *
in case somebody else gets confused like I did.
The reason why https was systematically returning a 404 when I was calling rewritten urls is because... My domain configuration file was incomplete, my website-ssl.conf was missing the AllowOverride All directive, this is why it was all working fine until I added the url rewriting. My non-ssl was correctly setup for url-rewriting so this is why it took me a little while to realise this was not working when https.
I have then added the necessary in my /etc/apache2website-ssl.conf
<Directory /var/www/vhosts/exemple.com>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
and this in my .htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://exemple.com/$1 [R,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|css|js|robots\.txt)
RewriteRule ^(.*) index.php/params=$1 [L,QSA]
ErrorDocument 404 /index.php
I hope that'll help somebody.
Thank you for your help
Just keep the https redirection rule above other rules :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|css|js|robots\.txt)
RewriteRule ^(.*) index.php/params=$1 [L,QSA]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/index.php
</IfModule>
So in the above case, if user is going to http link, both(re-write to https and forward to index.php) will happen (i tried and its working). but if user is going to https directly, then you should have simple rewriting to index.php in your default-ssl
htaccess file which redirects my advanced Yii2 app to frontend index.php file for that there is already an .htaccess file. which has following lines..
This is Right Now my .HTACCESS at root directory
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
now i searched internet and i found this if i want to redirect to https then i have to add this.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
so i added like this....
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
then it loads website withouat any js and css... and also it is in http. But content it requires should be in https.
I do understand it is because of my another rewrite statement. But i am not so expertise in it. Please mae some suggetion.
Here this thing if it is alone it works perfect without any problem.
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
It will send my http to https. So it works perfact.
Or if this is alone
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
This rule tells that execute index.php file from the [.htaccess Directory/frontend/web/] directory . Means execute frontend/web/index.php . Here it is very important to do this as this is as per the framework structure.
So i have to combine these two rules together and build a .htaccess which will work for both scenario.
CONCLUSION
So my .HTACESS should tell the server we have to run [.HTACESS DIR/frontend/web/index.php] in https.
UPDATE TO QUESTION
this is the .htaccess under frontend/web/ folder where my index.php is
And this is at root/frontend/web folder where index.php exists.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Do i have to add https thing here ?
The easiest way might be setting the on beforeRequest event handler in /config/web.php like so:
...
'bootstrap' => ['log'],
'on beforeRequest' => function ($event) {
if(!Yii::$app->request->isSecureConnection){
$url = Yii::$app->request->getAbsoluteUrl();
$url = str_replace('http:', 'https:', $url);
Yii::$app->getResponse()->redirect($url);
Yii::$app->end();
}
},
...
You root/frontend/web/.htaccess should be like this:
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]
Just remember that a sub-directory .htaccess always takes precedence over parent directory .htaccess.
In root .htaccess when i put this. It also works for me.
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
Another approach would be to change the virtual host on port 80 (HTTP):
<VirtualHost *:80>
ServerName mywebsite.com
Redirect permanent / https://mywebsite.com
</VirtualHost>
and then have a separate virtual host for port 443 (HTTPS).
Assuming a Debian(-fork) Linux server you'd have to put the above in /etc/apache2/sites-available/myname.conf.
After you've done that use sudo a2ensite myname.conf (if this fails, you can create the symlink in /etc/apache2/sites-enabled/ yourself, but try not to). Now restart apache with 'sudo service apache2 restart'.
I've used this code below.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
I have used search and Google but can't seem to find a solution. I am trying to redirect it to HTTPS but am having some issues. I keep getting:
ERR_TOO_MANY_REDIRECTS
Below is my htaccess file. I would prefer that instead of adding a code to each html code. I have tried everything and just cant figure it out.
# Multiple Environment config
# Set this to development, staging or production
# SetEnv PYRO_ENV production
<IfModule mod_rewrite.c>
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
# disable the Apache MultiViews directive if it is enabled on the server. It plays havoc with URL rewriting
Options -MultiViews
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RedirectMatch 403 ^/.*/(system/cms/cache|system/codeigniter|system/cms/config|system/cms/logs|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
Edit: Problem solved Below code Worked. Please Lock
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://mydomain(dot)com/$1 [R,L]
try below code, it should work:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RedirectMatch 403 ^/.*/(system/cms/cache|system/codeigniter|system/cms/config|system/cms/logs|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I am trying to redirect visits to https://www.domain.co.uk to http://www.domain.co.uk. I have researched this, but have come to a dead end.
Many people including people here, on SO suggest to use:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This is my entire .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have tried putting the https rewrite code above, below and within the <IfModule mod_rewrite.c>. But had no luck.
I know the .htaccess is being read, as I can make it return a 500 internal server error when using random letters.
Thanks for your help.
EDIT
Anubhava found out my server isn't listening for port 443 as my VirtualHost has no entry for it.
Here's that section of my httpd.conf
If it is WP then in your permalink settings change your site's URL to http://domain.com which seems to be https://domain.com at present. WP forces that URL if you're using a different one.
Your full .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>