2

I have installed the Laravel 5.2 in my Linux Server And I made it so hardly by modifying the HTACCESS file , So now I'm trying to make a redirection from the www to the non-www version I mean like stackoverflow from www.example.com >>TO>> example.com , But I'm afraid because I may crash my server so please help with the explanation of the code please :

RewriteEngine on 

# I changed my website real name to example
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 

RewriteCond %{REQUEST_URI} !^/example/ 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ /example/$1 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteRule ^(/)?$ example/index.php [L]

Thanks in advance

Khalil Bz
  • 557
  • 1
  • 9
  • 24
  • What is `/example/` directory? What is full URL to access your Laravel home page? – anubhava Sep 09 '16 at 16:41
  • yes "example" is a directory because the Laravel Project have to be hidden from the public access , this is what I've been told to do in the tutorial – Khalil Bz Sep 09 '16 at 16:47

1 Answers1

1

You can try these rules:

RewriteEngine on 

# I changed my website real name to example
RewriteCond %{HTTP_HOST} ^www\.(.+)$ 
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301,NE]

RewriteRule ^/?$ example/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(?!example/)(.*)$ example/$1 [L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I'm sorry for not answering you until now :) , It's working but there is a problem when I go to `www.example.com/ex1/ex2/ex3.php` it redirects me to `example.com/index.php` , but I want it to redirect me to `example.com/ex1/ex2/ex3.php` , I mean I want to keep the parameters , and sorry for bothering you ^__^ – Khalil Bz Sep 10 '16 at 07:06
  • Completely clear your browser cache while testing this. Do you have any other rule or any other .htaccess? – anubhava Sep 10 '16 at 08:04