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?
Related
I would be very grateful if someone could answer.
I am trying to install my laravel project to virtual host. The server
runs on nginx.
Everything is ok except assets file.
The problem is the server does not load assets files. To be more exact:
asset()
function doesnt point to public path.
But the URLs (routes) are working perfect.
I copied htaccess files from public path to root.
Here is my htaccess files content:
<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}]
Any helps guys! Thank you very much!
Laravel is throwing a 404 error on my images, css and javascript files which are located in /mysite/public. I've set /mysite/public as the site's root folder and all my assets are located in there.
I did a google search on this error but they all gave the same solution i.e {{asset('css/style.css')}}. I already have my links setup like this so I don't think this is the problem.
I think the error has something to do with my Rewrite rules but I just can't figure our what it is.
My site's .htaccess file is:
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.my-site.com/$1 [R,L]
</IfModule>
If I delete the first RewriteRule, my css loads fine but pages other that the homepage will start throwing a 404 error. If I put it back, other page work fine but css, js and image file stop loadings.
Your first rule essentially says "regardless of what the URL is, load index.php". This means it will never load your assets, which are physical folders, as it will just load index.php instead. For example, if you tried to load css/image.png it will just load index.php.
If you remove it, your actual folders will load, but other URLs aren't re-written to index.php, which is why it will break.
You should use the .htaccess provided to you by Laravel. This should be your .htaccess file in the public/ folder (as per the Laravel Github repository)
<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}]
</IfModule>
public/.htaccess
If the public folder is not the root on your server, you'll also need to have this in an additional .htaccess (in the folder above public)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
/.htaccess
add this rule to keep assets from being routed to the router
RewriteEngine On
# Don't rewrite for css/js/img assets
RewriteRule ^assets/.* - [L]
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.my-site.com/$1 [R,L]
Got flamer script (http://provenlogic.xyz/flamer) installed and configured but start to get problem just in Opera and Chrome (in Firefox and IE works fine).
Here is my installation http://chronogym.com/flamer
The same url causes endless loop in Chrome and Opera and works fine in FF.
First question is how it could depend on browser, because I thought that redirections are driven only by server side.
Another question: when adding something like dd('test'); somewhere in controller even in FF script begins to brake connection instead of showing dumping result.
Project is placed in subdir on server: root/flamer. In root I got other project. I suggest that .htacces from that project can cause problems or conflicting with .htaccess from flamer but can't find out the exact cause.
root .htaccess
ModPagespeed off
RewriteEngine On
RewriteBase /
#Options +FollowSymlinks
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(_css|_js|memberarea)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
ErrorDocument 404 http://www.chronogym.com
RedirectPermanent /coaching.php http://chronogym.com/2-0-coaching_minceur.html
subdir .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.chronogym.com/flamer/$ [NC]
RewriteRule ^(.*)$ http://chronogym.com/flamer$1 [R=301,L]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Your middle rule is not correct but that would conflict anyway. You need to use RewriteBase if this .htaccess file is in the flamer folder. Have your rules like this.
RewriteEngine On
RewriteBase /flamer/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
On my domain public directory is the laravel public directory.so there is index.php and htaccess file. but i want to access mydomain.com/demo/, where demo is a folder.its always redirect me to my home page as mydomain.com because of route rewrite . so how can i access folders in mydomain.com. my htaccess is followed. ...
<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>
thanks in advance
Create a separate .htaccess file within demo directory to override the .htaccess file in your root directory.
Order Allow,Deny
Allow from all
Create a separate .htaccess (as Brian Dillingham said) file within demo directory to override the .htaccess file in your root directory.
But put use codes below instead:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Also, you can refer the answer from: https://stackoverflow.com/a/38068912
For the ones out there who use a public domain but the Laravel directory is within a subdirectory. You might have the following folder structure:
- / <-- directory your domain (e.g. "https://example.com") points to
- some_subfolder1/
- some_subfolder2/
- laravel_project/
- ...
- public/
- .htaccess <-- File one has to modify
- index.php
- ...
The .htaccess File's RewriteRule for Front Controllers would look the following:
RewriteRule ^ laravel_project/public/index.php [L]
So you will end up with:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# 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 ^ laravel_project/public/index.php [L]
</IfModule>
In addition, I also modified the .env-File for the APP_URL param:
APP_URL=https://example.com/laravel_project/public
Furthermore, you might think of moving the laravel project files (despite from the public folder) outside of this file tree.
I have a blog set up at blog.ftj.com/ACSM, it is hosted with Bluehost and their folder structures seem to be case sensitive. Is there something in the .htaccess file that I can adjust so that all possible combinations get redirected to the specific uppercase URL.
Another issue is that it seems that I need to redirect
blog.ftj.com/acsm/
with and without the forward slash.
Here is my current .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ACSM/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ACSM/index.php [L]
</IfModule>
# END WordPress
Please submit the full change if you would.
You need to place the following .htaccess in the root dir to rewrite all requests to /ACSM into /acsm
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/acsm$ [NC]
RewriteRule ^(.*)$ /ACSM [L]
RewriteCond %{REQUEST_URI} ^/acsm/(.*)$ [NC]
RewriteRule ^acsm/(.*)$ /ACSM/$1 [L]
</IfModule>
Sorry for delays, have not got an Apache at hands....