https with url rewriting - apache

When I enable https on my website, the url rewriting doesn't work ( not found ... )
My htaccess:
# URL Rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
# Full path to your site
#
RewriteBase /
# 301 redirect if missing www.
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ https://www.% {HTTP_HOST}/$1 [R=301,L]
#RewriteRule ^(static/|ajax\.php) - [F,L,NC]
# 301 redirect if missing trailing slash
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
# Rules
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?do=/$1
</IfModule>
How can I enable https with url rewriting ?

You have AllowOverride None in <Directory /var/www/> entry which means .htaccess isn't enabled.
To enable .htaccess change that to:
AllowOverride All
And restart Apache server.

You need to uncomment the lines first I think.

Related

My fowards do not seem to work in .htaccess

I have an issue with an apache .htaccess redirection on a laravel site
My forwards do not seem to work
here is what I want:
Foward www to non-www www.ReplaceMe.com to ReplaceMe.com
Foward HTTP to https http://ReplaceMe.com to https://ReplaceMe.com
Foward non-trailing / to add trailing / https://ReplaceMe.com to https://ReplaceMe.com/
so the result would be.
https://www.ReplaceMe.com/about-us TO https://ReplaceMe.com/about-us/
But it does not seem to be working.
Below Code i am using now:
<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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# www to non-www
RewriteCond %{HTTP_HOST} ^www.ReplaceMe\.com$ [NC]
RewriteRule ^(.*)$ https://ReplaceMe.com/$1 [R=301,L]
# http to https
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
</IfModule>
As far as I know, this should work. Can anyone spot my Issue?

Laravel: .htaccess rule for redirecting to https not working

I'm developing a laravel app and I need to force HTTPS for it.i've tried many other solutions that i found on the internet but none of them worked.is it possible that my app some how ignores htaccess rules?
i've already tried these solutions:
Laravel: how to force HTTPS?
here's my httaccess file :
<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]
# Handle redirect to Https
RewriteRule ^(.*)$ https://foody.ir/$1 [R,L]
</IfModule>

How to redirect users using .htaccess?

I am using Apache on my VM. I have this .htaccess right now.
<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>
Result
If I do
http://dips.awsri.com/
it works fine.
If I do
http://www.dips.awsri.com/
it redirects me to my log in screen, which I don't want 😓
http://www.dips.awsri.com/login
How can I stop that ? and instead redirect my user to
http://dips.awsri.com/

Codeigniter mod-rewrite in apache, removing index.php

So I am quite new to codeigniter and I have been trying to get my head around removing the index.php from my local site, I have managed to make it work for the homepage after looking through other similar questions on SO but none have got it fully working. Whenever I visit another page on my site it displays the wamp page on my screen. Here is my code in codeigniter/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I have also put in my apache/conf/httpd.conf
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
But still no luck, is there something I've missed? Thanks in advance
Follow the following step:
1. Change the config file like this:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.Use the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: .htaccess vary depending on server. I some server (e.g.: Godaddy) need to use the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Use this .htaccess works on most servers
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
You can uncomment the last 2 lines to force HTTPS.
Also this could also work
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Note line 3 of the 2nd .htaccess RewriteBase /foldername/ use this RewriteBase / if your script can be reached without including a folder name.

Consolidating .htaccess and fix bug

I should start off by saying that I am no expert with .htaccess and that everything I have done with it comes from tutorials I followed.
I have edited the stock standard .htaccess file that ships with Laravel to include lines that
remove public from the URL
force https
redirect requests for www.mysite.com to mysite.com
The issue that I have currently, is that when I visit the route mysite.com/sitemap or www.mysite.com/sitemap it generates a new sitemap and then redirects to mysite.com/index.php effectively getting rid of the pretty-urls that Laravel is meant to fix.
This is my .htaccess file in my public directory:
<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]
# Redirect www.mysite.com to mysite.com
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
This is the .htaccess file in my root directory
# Remove public
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
And this is my routes.php handling the sitemap route
Route::get('sitemap', function(){
// create new sitemap object
$sitemap = App::make("sitemap");
// add items to the sitemap (url, date, priority, freq)
$sitemap->add(URL::to('/'), '2015-11-14T20:10:00+02:00', '1.0', 'monthly');
$sitemap->add(URL::to('getcv'), '2015-11-14T12:30:00+02:00', '0.9', 'monthly');
// generate your sitemap (format, filename)
$sitemap->store('xml', 'sitemap');
// this will generate file sitemap.xml to your public folder
return redirect('/');
});
My question is, how can I make it so that mysite.com/sitemap or www.mysite.com still follows all of the rules in my .htaccess whilst redirect to mysite.com after following the sitemap route rather than going to mysite.com/index.php?
You need to reorder your rules in /public/.htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect www.mysite.com to mysite.com
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [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]
</IfModule>
Make sure to clear your browser cache when you test this change.