2

Consider this is my domain www.example.com

I am using laravel in my website

This is the laravel structure

app/
bootstrap/
public/
vendor/
server.php

To remove the index.php and public from the url i followed this answer

i.e.,

had the .htaccess in the root path

and renamed the server.php file as index.php

Here is my .htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

It works good, but the problem is i am having subdomain as

projects.example.com

While i create a sub directory here i.e.,

projects.example.com/firstproject

It always shows the internal server error

How can i fix this like, having exception to that directory or something like that ?

Community
  • 1
  • 1
AngularAngularAngular
  • 3,589
  • 5
  • 25
  • 41

1 Answers1

10

The htaccess file affects the directory the file is in and all subdirectories. If you have subdirectories that you don't want mod_rewrite rules to affect, then you need to add an htaccess file with in the subdirectory with the rewrite engine turned on (so that none of the parent rules have precedence).

Just add this to an htaccess file in your subdirectory without any actual rules:

RewriteEngine On
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I have created the .htaccess and added the rule you suggested.. My target folder is `projects.example.com/firstproject` i updated the `.htaccess` here but it still shows the error – AngularAngularAngular Feb 06 '15 at 06:11
  • Check your error logs to make sure that the error is actually caused by mod_rewrite – Jon Lin Feb 06 '15 at 06:12
  • It works great !! Asking for clarification... If i add `RewriteEngine On` in the .htacess anywhere the rules in the previous directory won't work right ?? – AngularAngularAngular Feb 06 '15 at 06:15
  • 1
    @Chennai correct, it sounds counterintuitive, but if you don't have the rewrite engine turned on, there are no rules and thus any rules in parent directories automatically get applied. If you have the rewrite engine on, then the rules in the current directory get applied (which are none). – Jon Lin Feb 06 '15 at 07:10