I want to remove my public folder from url and want to force http to https.
I am using this
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://{REQUEST_URI} [L,R=301]
this code only works for remove public but not work for http to https
For Remove Public folder
1. Move the .htaccess file from public folder to main folder.
then Rename the server.php to index.php
Now the myproject/public/ is changed to myproject/.
For htaccess
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I Hope this will help for you. Thank You
Related
The old .htaccess redirects automatically to https protocol :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
But I saw there is no pointer to the subfolder via htaccess. The ex-developper used this :
[root]index.php
<?php include_once("wordpress/index.php"); ?>
It seems to create several bugs :
on the admin panel side, there is a redirection https://my-site/wp-admin/ to https://my-site/wordpress/wp-admin/ but not on the front-end.
Sometimes on the admin side, there are some redirection like this : https://my-site/wp-admin/... which generates bugs.
So... It´s confusing and I wish to clean this with a simpler way : I would like :
point the domain to the subfolder wordpress and works for front-end and back-end
keep the automatic redirection http to https
I tried this without success :
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^(www.)?docpeda.be$
RewriteRule ^(/)?$ wordpress/index.php [L]
</IfModule>
I´m sure it´s really easy to do it but I need some helps.
This is what you should put in the .htaccess file if it's a subfolder, hopefully this will solve your issue (just copy and paste). It will also make the site secure.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^(www.)?docpeda.be$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1
RewriteCond %{HTTP_HOST} ^(www.)?docpeda.be$
RewriteRule ^(/)?$ wordpress/index.php [L]
</IfModule>
I am trying to write the correct rewrites in my .htaccess file in order to have all non-www. and https:// requests redirect to https://www.example.com whilst also having the domain invisibly redirect to a subdirectory "build" as the base directory.
So if the index.html is in home/var/www/example.com/public_html/build/index.html the URI path still needs to be https://www.example.com/index.html.
I do have all but the non-www. part redirecting correctly, just cannot get that part working also.
Any help will be greatly appreciated.
RewriteEngine on
RewriteBase /build
RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
RewriteCond %{REQUEST_URI} !^/build/
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
RewriteRule ^(.*)$ /build/$1 [L]
Thanks in advance.
My Laravel project is already inside in shared hosting server(i know what do you thinking...). And inside root folder i got a .htaccess file which has this code:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond $1 !^(public)
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
This gives me good URL's without "public" but there is one case:
If i go:
www.example.com
so it always stays with URL www.....If i go:
https://www.example.com
it always stays with URL https://....
My question:
How to make that the URL would always be https://www.example.com whatever I enter www or https first?
This should do:
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
You can do that by putting following lines in the .htaccess files
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^.*$ https://%{HTTP_HOST}/public%{REQUEST_URI} [L,R=301]
</IfModule>
Put the code in .htacces in your laravel root directory, it should do the job:
RewriteEngine On
# enforce https
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
# use public directory as root, but don't include it in url
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
I have an integrated SSL for my entire site and have placed htaccess code to redirect to https when anyone visits my domain URL. But I want to keep one folder out of this redirection to https. Please help me with this... Below is the htaccess code placed in my root to redirect all requests to https counterpart
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Thanks
Just add a condition to exclude the folder:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/folder1
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
And if you wanted to redirect SSL requests to non-SSL for /folder1, then:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/folder1
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I would like to modify my .htaccess file so that when someone comes into my site without typing www the site always redirects them to the www version. For example, if my url is www.abc.com and they just type abc.com, I want to redirect them to abc.com.
Here is my current htaccess file:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Normally I know how to do the redirect, but im having issues since it already has those few lines in there.
I use the code below. It can be used for any domain name. You just need to enter it in your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
(edited to have all the code in the same block)
Add something like this immediately after RewriteEngine on:
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
There are two methods available
1) use mod_alias apache module
Redirect permanent /something http://yourwebsite.com/something
2) Add the following entry in your .htaccess / http.conf / yourwebsite.conf in the webserver configuarion directory
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourwebsite.com
RewriteRule ^(.*)$ http://www.yourwebsite.com$1 [R=permanent,L]
If you want redirect example.com to www.example.com you can try below code
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]