So i have recently installed SSL on my web application All routes are working fine but in case of APIs I am getting 404 error
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^1.1.1.1
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
if i disable SSL, All is fine.But i want to redirect every request overs https and get the result same as http.
Related
How to make that my laravel 5.8 site always works with https://www. prefix ?
In .htaccess i wrote
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RedirectMatch 404 /\.git
# RewriteRule ^$ info.php [QSA]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
But looks like RewriteRule is not applicable is some case when I run url like “mysite.com” browser redirects “https://mysitede.com”.
Also to be sure that I work https in my app/Providers/AppServiceProvider.php I have :
class AppServiceProvider extends ServiceProvider
{
use funcsTrait;
public function boot()
{
if( $this->isHttpsProtocol() ) { // check I am not on local server
\URL::forceScheme('https');
}
Which is the decision ?
The following .htaccess code redirects requests to the https and www versions of your web pages. Add to your site's root .htaccess file:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]
WordPress has been installed on the root of the production server and my Lumen framework is in public_html/developer/api folder but when we try to access api folder through url it is showing WordPress 404 page not found error. One htaccess file has put in api (Lumen) folder and another in /developer/api/public.
htaccess file code inside api folder:
RewriteEngine On
RewriteBase /developer/api/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond $1 !^(index\.php|images|quotes|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /developer/api/public/index.php/$1 [L,QSA]
and inside api/public:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
In my Laravel app I added to the /public/.htaccess/ file a RewriteRule like this:
RewriteRule ^resources/pdf/?$ /about
however, if I call www.mydomain.com/resources/pdf/ the I only get this error:
although my server uses APACHE and the other htaccess entries do work. Also www.mydomain.com/about does work.
Why is this not working? Here is the full htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteRule ^resources/pdf/?$ /about [L]
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Try with:
RewriteRule ^resources/pdf/?$ about [NC]
Which works with www.mydomain.com/resources/pdf/ and www.mydomain.com/resources/pdf
I was missing the [L]:
RewriteRule ^resources/pdf/?$ /about [L]
Also I had to clear cache and view the page in incognito mode to witness the effect.
Redirect works only on the first page, http://example.com to https://example.com.
But it doesn't work on subfolders: http://example.com/news or /news/category etc. redirects me to the https://example.com/index.php (My website is on Laravel 5.5).
Any suggestions pls?
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# ensure !www.
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Header add Access-Control-Allow-Origin "http://glyphicons.com/"
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Remember to replace example.com and www.example.com with your actual domain name
I have a website that home page is in site.pt/pt/home so I need to put in .htaccess but I don't know how...
I have this code:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
How can I do that?
Thank you.
Try putting this just after RewriteEngine On:
RewriteCond %{REQUEST_URI} !^/pt/home [NC]
RewriteCond %{REQUEST_URI} !^/pt/home/.* [NC]
RewriteRule ^(.*)$ /pt/home/$1 [R=301,L]
The two conditions are for skipping request that start already with /pt/home and the rule redirect all other requests there.