I just made a simple laravel application in CentOS running in apache server. The thing is I always gets an error:
"Not Found" when redirecting to other pages.
How do I fix this ? I'am completely new on using CentOS and apache server.
Note: It is working fine with Windows and xampp.
Here is my .htaccess file
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]
Try that route with index.php? like yourdomain.com/index.php/route-url and check if it works. If your homepage works and other pages do not, then your rewrite rule is no set.
Do
sudo a2enmod rewrite on
your server terminal and then restart apache
In Apache virtual host section add
AllowOverride all
And in your laravel's .htaccess add this :
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
It's likely that you don't have Apache set up to properly rewrite your route and hand it to the index.php file. Have a look at the Apache section near the bottom of this page and ensure that your redirects mirror what this page lays out.
Related
I am trying to change .htaccess file.But changes are not reflecting. Laravel home page works properly even if .htaccess file contains errors.
I have gone through the checking of mod_rewrite enable and apache2.conf files.Everything is perfect but unable to find the issue.
gfdghfguf;l;..
hfjffgfgh
lghkjgkjg
jfghkfhjfgh ghggggggggggggb
Options -MultiViews -Indexes
RewriteEngine On
gb gjf jfhgj jfhg jhfjf g
# 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]
It have to give 500 internal server error but it works fine.
Pulling my hair out. I need to force to HTTPS and getting too many redirects with the below in .htaccess file. Based on my research on Stack, this should work. Cleared cache, cookies, all that.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} off
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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Ok, figured it out. Because I'm behind a load balancer, I had to replace:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
WITH:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]
More info on why you need that header here: Load Balancers and HTTPS
I had a similar problem (with Codeigniter and using AWS Classic ELB) but the above solution did not work for me. I had to apply the rewrite conditions and rules in the https.conf file and then restart the apache server. See here for how to do it. Also worth noting that AWS don't recommend the .htaccess approach (not sure why):
https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/
https://www.youtube.com/watch?v=hvqZV_50GlQ
I had a similiar problem with Laravel 6 on a shared hosting. When I configured CPanel to redirect my app to a secure https url, it kept redirecting infinitely.
I had this in my .htaccess
RewriteCond %{HTTP_HOST} ^biblioteca\.vallenateca\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.biblioteca\.vallenateca\.com$
RewriteRule ^/?$ "https\:\/\/biblioteca\.vallenateca\.com" [R=301,L]
I added this two lines.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^biblioteca\.vallenateca\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.biblioteca\.vallenateca\.com$
RewriteRule ^/?$ "https\:\/\/biblioteca\.vallenateca\.com" [R=301,L]
And it solved it.
In laravel 8, the default on the .htaccess file is:
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
This worked for me and I'm using Inmotion hosting:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]
I'm using Laravel 5.5.
Laravel has couple of .htaccess and in my case I'm working with .htaccess on root and inside the public folder.
All this time I was using this code in root .htaccess to setup the public folder:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
and my website is loading when I enter the homepage.
After that, I wanted to force redirect all the pages using https. So, first when I try to put this code inside the root .htaccess it doesn't do anything. It keeps loading with http.
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Well, it makes sense, because when I setup the public folder, I have to put the redirect inside the .htaccess that is located inside the public folder.
OK, so I've tried like this now:
The root .htaccess:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
The public .htaccess
<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>
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This combination works. It does redirects to https.
But, there's one issue now. When I enter the homepage or if I open the website from the search results, the URL looks like this:
https://mywebsite.com/public/en
When I enter the other pages, I don't have issue related with the "public" path in the URL. So, let's say I want to open the contact page, the URL is https://mywebsite.com/en/contact. That's fine.
How can I avoid that "public" in my URL when I enter the homepage?
This should remove public from the url.
RewriteRule ^(.*)$ public/$1 [L]
I am not sure if this should go above
# Handle Front Controller...
or within it? Maybe try either one and see if either work?
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
RewriteRule ^ index.php [L]
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
source
Hi I currently have a site setup where magento is installed in a subdirectory called magento
ie.
http://domainname.com/magento/
So the base URL is set as http://domainname.com/magento/ and secure base URL is https://domainname.com/magneto/
What do I need to do to get it so everything working so it can be referenced as http://domainname.com
Hi you can achieve this by using.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/magento/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /magento/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^(/)?$ magento/index.php [L]
for reference you can see change-main-domain-to-subfolder
Change DocumentRoot in Apache Http Server's config file. /etc/apache2/httpd.conf or /etc/apache2/apache2.conf. change it to /var/www/html/magento or /srv/www/htdocs/magento according to your os.
i have problem about .htaccess file for my codeigniter installation.
On localhost this work fine, when i upload online its rewrite URL but the website not work.
this is my htaccess on localhost:
RewriteEngine On
RewriteBase /jCore_01/
#RewriteBase /
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
online i have a problem:
i put this file on subdomain jcore.miodomio.com and it rewrite URL but not work
example:
without htaccess it's work:
jcore.miodominio.com/index.php/en/home
with htaccess
jcore.miodominio.com/en/home
Not Found
The requested URL /en/home was not found on this server.
can anyone help me? suggestion?
regards
Denny
Try change your htaccess to:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Somethings to consider.
Did you enable Apache rewrite module?
If enabled check whether your virtual host file is configured properly So to make sure its hitting .htaccess or try putting some dump on .htacess , So if its hitting .htaccess than you should get an 500 server error.
If you are not getting error than its mostly the problem in your host settings.