In the public directory, I have a subfolder /app that contains an angularjs app. I'm trying to achieve the following situation:
User navigates to /, /about, /contact, etc and sees site as handled
by laravel.
User navigates to /app (and any of it's child URLs) and is redirected to that
subfolder (i.e. not handled by laravel's index.php.
How can I achieve this using the .htaccess file? Current file is:
<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]
</IfModule>
I added a redirect to the .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteRule ^((?!app/).*)$ /app/$1 [L,NC,R=301,NE]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Related
I have a blog folder in my servers /home/app/sites directory, and I have my laravel app in /home/app/public_html/laravel and my domain www.laravelapp.com is pointing to the project.
I want to point the url www.laravelapp.com/blog to my blog folder in /home/app/sites/blog.
How can I do that?
Here is my .htaccess file:
<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}]
# Redirect blog folder (Not working)
RewriteCond %{HTTP_HOST} ^www.laravelapp.com/blog$ [NC]
RewriteRule ^(.*)$ /home/app/sites/blog [L,R=301]
</IfModule>
../ goes one folder down
So it should be ../../sites/blog
There may be restrictions with htaccess. If this not already work share your .htaccess file. You cant go behind your base url, the following question explains it very well.
Having links relative to root?
Updating a site and have a ton of redirects.
The issue is that the new URL retains part of the old for all, as seen in the following example:
Redirect 301 /old/oldfile.html /new
redirects to:
http://url.com/new/oldfile.html
Aside from the redirects the htaccess contains the following:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
Options +FollowSymLinks
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
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>
Use mod_rewrite instead. This should go above the other rewrite rules.
RewriteEngine on
RewriteRule ^old/oldfile.html /new [R=301,L]
Here's my .htaccess file
<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]
</IfModule>
I need this www.domainname.com/folder-name/
to rewrite/redirect to this
www.domainname.com/folder-name/index.html
without screwing up what's already in htaccess.
So i'm clear...when it's all said and done i want www.domainname.com/folder-name/ to display in the URL bar, but I want the content from index.html to be rendered.
You have a problem in that if you go to www.domainname.com/folder-name/, your first rewrite rule will redirect you to www.domainname.com/folder-name, removing the trailing slash. Assuming you haven't turned off DirectorySlash, mod_dir will redirect this back to www.domainname.com/folder-name/, which then triggers the rewrite rule, which triggers mod_dir, etc. If you've turned off DirectorySlash, that means you've exposed an information disclosure bug (or "feature") which will list the contents of the folder-name folder even if index.html exists.
So if you really want to be able to go to www.domainname.com/folder-name/ and not lose the trailing slash, then you need to add a condition to your first rule and then simply allow mod_dir to do its thing:
DirectoryIndex index.html
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
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>
If you've mistyped and you actually want all the trailing slashes to get removed including for folders, leaking the folder contents and all, then you've got to do a bunch of other things. Essentially, you have to do what mod_dir normall does for you anyways and make sure DirectorySlash is turned off (still dangerous, as it could expose the file listings of all your folders):
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
DirectorySlash Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{DOCUMENT_ROOT}/$1/index.html -f
RewriteRule ^(.*[^/])$ /$1/index.html [L]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I want to remove the index.php from the url to access the controller action. Therefore I added the following code in my .htaccess file in the public/ folder:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I would be grateful if anyone reply me and solve this issues.
Why don't use the default Laravel .htaccess file. You should go fine with it.
<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]
</IfModule>
I'm a beginner when it comes to doing stuff with htaccess so please be patient with my dumb question. I know that this has been addressed a lot (here, here, and here for example) but it doesn't seem to work for my situation. My browser displays a "redirect loop" error with this code in my htaccess file:
<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]
# Trying to redirect to https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
I know that this probably has something to do with the RewriteCond and the RewriteRule before I redirect to https, but I don't really know what I'm doing here and I don't know what to change.
Update:
Some more info that might be helpful:
When I remove the "redirect to https" code and manually type https://my.site.com it loads just fine.
Also, the redirect-to-https thing worked great before I accidentally deleted the .htaccess file in my directory.
The app that I'm trying to redirect resides in a subfolder of another app which also has an .htaccess file. Here's the code for that app:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine On
</IfModule>
This is what firebug says:
Change order of your rules and keep 301 rules before other internal rewrite rule:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Trying to redirect to https
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>