My old domain: domain.com
My laravel project in: domain.com/laravel/public
It's working well, but I don't want see public in URL.
I add new .htaccess file to my root laravel folder (domain.com/laravel/.htaccess) with:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
When I access to domain.com/laravel, my jQuery path is: domain.com/js/jquery.min.js
When I access to domain.com/laravel/public, my jQuery path is: domain.com/laravel/public/js/jquery.min.js
I don't want move all files in public folder to root folder, because really more files there.
Best regards,
I read more answers in more website, almost their said move all files in public folder to root folder of Laravel application.
It's not good if we have more files there, so, I was try with some way and finally, I just move index.php and .htaccess file to root application.
It's working well, I just change some code when using HTML::script, HTML::css and {{ asset }}
As normal, we using HTML::css('style.css'), I just add public before, like this: HTML::css('public/style.css')
I hope it helpful for someone.
Best regards.
This is my current solution:
<IfModule mod_rewrite.c>
RewriteCond $1 !^(public)
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
You have to add a rewrite condition.
Related
I want to access my Laravel application through a directory in a subdomain in a shared host; as in sub.domain.com/dir. I want to be able to properly hit the app routes as sub.domain.com/dir/posts.
Thus, I've set the APP_URL=https://sub.domain.com/dir/ in the .env file. It works through sub.domain.com/dir/public; but the relatively-addressed media are inaccessible; they are referenced as sub.domain.com/path/to/asset, while they should be sub.domain.com/dir/path/to/asset:
sub.domain.com/dir/path/to/asset <--- accessable: Expected
sub.domain.com/path/to/asset <--- inaccessable: What is given
In an attempt to drop the /public part, I've put the following code in an .htaccess file inside of <docroot>/dir directory:
RewriteEngine On
RewriteRule ^(.*)$ /dir/public/$1 [L,QSA]
It seems to be effective on dropping the /public part (let me know if there are issues with that).
Here is the main issue: considering the web.php file to be like:
Route::get('/{num}', function ($num) { return "Number: $num"; })->where('num', '\d+');
Route::get('/{any}', function ($any) { return "Other: $any"; })->where('any', '.*');
Accessing sub.domain.com/dir/123, gets Other: dir/123 instead of Number: 123: Laravel considers the /dir/123 as the routing matter, while I want it to treat the /123 as the routing matter. The same issue causes the assets to not to originate from sub.domain.com/dir but rather from the subdomain root: sub.domain.com, without the /dir suffix).
I want the sub.domain.com/dir to be considered as a whole (as if the /dir is part of the domain, in that the relatively-addressed media would be accessible); and what follows the /dir part, to be fed into Laravel app for routing and all the other stuff.
So, how should I setup my Laravel app in a subdomain-directory in shared host?
Put these lines of code in your laravel root directory .htaccess file, which might be in your sub.domain.com/dir directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
that will solve your /public problem.
For the Media assets, did you used the asset URL helper function to link the media assets?
I'm going crazy here! I'm trying to learn Laravel and pretty URLs just don't work.
I have enabled mod_rewrite from my apache config file, I have set AllowOverride to All in my user config file and I have the following in my .htaccess file in public folder of Laravel installation:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
I enter http://localhost/~user/lara/public/index.php/users it works, but with http://localhost/~user/lara/public/users I get 404 Not Found error
The requested URL /Users/user/Sites/lara/public/index.php/users was not found on this server.
You can see that the redirection works fine, as public/users have turned into public/index.php/users but it says not found, even though when I manually enter public/index.php/users it show me the output.
I have read all the related questions on SO, none of the worked for me!
This is most likely caused by the fact that you are changing the document root during a request. From the looks of your URL (with the ~user segment) you are using mod_userdir or something similar, and what these types of plugins do it allow you to map a given URL prefix to a document root that is not the normal one for the server.
As such, you sometimes run into issues like this where the right .htaccess file is found, but its rewritten URL is against the original document root rather than the modified one and so your index.php file cannot be found (maybe, to be honest I don't really know, this is all conjecture). This is also why going directly to index.php/users works - the problem isn't the setup per se, but the mixing of rewrite rules and the change of the document root.
As such, the fix is to use a RewriteBase line, ad the following to the .htccess file:
RewriteBase /~user/lara/public/
Why i can't get an image to work. I'm trying this:
background-image: url(jBootstrap/images/ui-icons_222222_256x240.png);
and it doesn't work. When i'm trying to access it trought URL i get an error:
Asset [stylesheets/jBootstrap/images/ui-icons_222222_256x240.png] was unable to be processed.
Can't get any images, tried in many variations of directories and still doesn't work. When i'm doing this on plain html-css it works perfectly, but not in laravel. What am I doing wrong ?
btw, i'm using Basset if it helps.
EDIT 1
Also including the additional information about a partial structure of my public folder and html link generated by basset:
public/
stylesheets/
jBootstrap/
images/
ui-icons_222222_256x240.png
main.css it contains the background-image...
when including the css file, in source code i see:
<link rel="stylesheet" type="text/css" href="http://localhost/Job/worker/myapp/public/7n3C5wypAmTi8VT8/application/stylesheets/main.css" />
Edit 2
Adding my public/.htaccess file:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Edit 3
Tried another way:
public/stylesheets/main.css
public/stylesheets/abc.jpg
in main.css I have code: body { background-image: url('abc.jpg') } and i'm getting nothing ...
Please help, struggling 2 days now ...
Found the problem... It was Basset package, it wat required to put $collection->apply('UriRewriteFilter'); into configurations.
I would naturally assume that one (or both) things are incorrect here:
Your .htaccess file is not checking for existing files when rewriting. Check to see if RewriteCond {%REQUEST_FILENAME} !-f exists in that file.
You are not requesting your background image from the root, i.e. absolutely. Try requesting the resource using a leading slash. For example, instead of calling foo.png, try calling /foo.png.
Try using setArguments('../') on your collection
'collections' => array(
'application' => function($collection) {
$collection->add('../vendor/twitter/bootstrap/less/bootstrap.less')->apply('Less');
$directory = $collection->directory('assets/stylesheets', function($collection) {
$collection->add('main.css');
})->apply('UriRewriteFilter')->setArguments('../')->apply('CssMin');
}
),
This did the trick for me.
I need to change abc.mydomain.com/xyz.php?id3=se
to abc.mydomain.com/xyz/se/ with url rewriting.
Here is my code in .htaccess (placed in abc folder)
Options +FollowSymLinks
RewriteEngine on
RewriteRule /xyz/([0-9a-zA-Z]+) /xyz.php?id3=$1
I'm using a hosted server.
also tried without Options +FollowSymLinks but still doesn't work. appreciate any advice from someone please.
I guess you have to remove the "/" from "/xyz.php?id3=$1".
You are in abc folder '/www/abc', and your .htaccess is in the same folder, so the "/" makes the server thinks that the page xyz.php is in the root folder which is /www and not in /www/abc !
I had the same problem and I solved it this way!
So try this code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule /xyz/([0-9a-zA-Z]+) xyz.php?id3=$1
Add the domainname in your rule:
RewriteRule http://example.com/xyz/([0-9a-zA-Z]+) http://example.com/xyz.php?id3=$1
I would like to create a .htaccess file that would do this logic:
If the requested file is not found try to find it in the directory
above.
I don't want to redirect the browser I would just like to internally rewrite the request.
I tried and searched for this a lot but always got stuck because (as I gather from the log) the where I could do the rewrite the path was always already without its per directory prefix. In the example below the .htaccess file is in the lang folder. If the lang specific file is not found it should just take the file from the parent folder. I understand that it is possible to do it by hardcoding the parent directory or by placing the .htaccess higher, but now that I suffered for so long in trying I would be very interested to learn if it was possible at all this way.
strip per-dir prefix: X:/localhost/htdocs/peopletest/public/img/root_cli/lang/en/loginhead.gif -> en/loginhead.gif
applying pattern 'somePattern' to uri 'en/loginhead.gif'
Thanks for the help.
SWK
Like this?
RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} !-l
RewriteRule /[^/+]/([^/]+)$ $1