Hi I am facing issues with settng pretty urls withput public in url but it is not working for me.
I already tried
Laravel 5.2 Pretty URLs,
Laravel 5 - Remove public from URL
and more similar urls but nothing seems to work for me.
I am using wamp, windows 8
I have make sure mod_rewrite is on, and is working properly.
Here is my htaccess on root.
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
my htaccess in test inside public folder
<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>
I have also tried pasting the htacess from public folder on root folder and removed the one from public folder but it dint work
actually the error which occurs is that my routes file skips all the patterns say if I have something like Route::get('/api/login', 'api#login') then it does works with urls containing public but when I remove public from url all the patterns are skipped. and it shows 404
I made sure all the requests are reaching public/index.php and mysterious thing is that when I print
var_dump(Request::root());
in routes.php it for url with public it says http://localhost/folderName/subFolderName/public but for the urls without public it says http://localhost/ and I think this is the reason why my patterns in routes file are not working.
P.S. I have set the title pretty urls laravel 5.4 instead of laravel routes not working because I think it is .htaccess which I needs to configure properly to get this working.
I do not want to change the folder structure because I believe in that there is some reason for which it is like this and There should be some work around for this.
Regarding setting vhosts I wont be able to do this on server (For I do not have the rights) so there is no use of setting a vhost on local as a work around as in login run I have to solve this.
Try this in your public/.htaccess
RewriteRule ^ /public/index.php [L]
And the .htaccess in root
RewriteRule ^(.*)$ /public/$1 [L]
Related
I am working on creating a website that converts text into speech. I am using the script from codecanyon which is Developed with PHP 7.4.x and Laravel 8.4.x . The issue I am facing is that I don't want to show /public URL as a permalink to access the website. Now, if I type mywebsite.com/pubic then the website is accessible otherwise if I write mywebsite.com then it only shows the files. I followed some of the previous queries posted on StackOverflow but got no results.
The topic I followed is Laravel 5 – Remove Public from URL
I tried even by renaming server.php , copying .htaccess and rewriting it. But those all resulted in a screen showing up errors or even blank.
My .htaccess file is;
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
To remove the /public from the URL you are not going to use the .htaccess file.
What you are going to do instead is set the /public folder as the serving directory for your Server.
If you use Apache, just go to your /etc/apache2/sites-available/000-default.conf file and change the DocumentRoot from {your base folder}/ (usually /var/www) to {your base folder}/public
The content of public folder should go to the public folder of your server (fe it's public_html on my server), and everything else should be stored in a different folder (fe laravel_mywebsite). Then you should go to public_html/index.php and change the folder paths based on where you put your Laravel app.
If you want to only use .htacces, you just need to rewrite all requests from /public to /
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]
I have a laravel app: https://laravel-app.com
I want to serve custom pages from a folder on the same domain https:laravel-app.com/player/player.php
I have set the .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /player/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /player/player.php [L]
</IfModule>
But when I try and navigate to that page by using this direct url: https:laravel-app.com/player/player.php
I get the laravel routing error: sorry, the page could not be found
Can someone explain how to get around this?
Anything you want accessible you can put in the public folder of your application, which should be the DocRoot/WebRoot. You won't need any special rewriting or rules as it will be an existing file so the server will serve it fine.
For the testing of a new version of a project, I have to deploy a laravel project to a sub folder which was set up for me. I already programmed it on the localhost and only need to upload it.
The subdomain is on example.com/new
The structure I found in Filezilla was like this:
(I do not have access/can't see to the main Versions files-does this mean it is a subdomain?)
htacess
env
newProject(folder)
public
I did not have permission to upload new files above the public folder. The .env and .htacess could be replaced. So I did the following:
htacess
env
newProject(folder)
public
index
project(folder)
(laravel put another.env and .htacess in here are these the right ones to change)
.htacess
.env
rest of laravel files
Out of confusion I always just make a change in both existing .env's and .htacess because I don't know which is the right one. Is this setup right? I already changed the index
require __DIR__.'/project/vendor/autoload.php';
$app = require_once __DIR__.'/project/bootstrap/app.php';
My htacess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
[[rewritebase /new
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
MY PROBLEM:
There is at least something working. Because I have an automatic rerouting for languages in the web.php
Route::redirect('/', '/en');
Route::group(['prefix' => '{language}', ''], function (){
...routes
And when I go to example.com/new it reroutes me to example.com/en instead of example.com/new/en. That means it does come to the routing part, dies this mean htacess and .env are set up right?
the error is of course
"Not Found
The requested URL was not found on this server."
MY QUESTION
How do I stop the rerouting to /en and go to /new/en. Is there a prefix I can add to all my routes. And can I be sure the rest is set up right just because the code routes to /en which is set up in the web.php?
I was given a laravel project I need to get up and running. I am new to laravel, but after allot of work, I believe I got everything configured properly and I deployed the project to heroku.
When I do artisan serve on my guest machine in my laravel project and go to the given url everything works fine all the links works.
But I deploy it to heroku and my index page shows but none of the links work.
I get:
Not Found The requested URL /register was not found on this server.
It seems that running php artisan serve kinda activates the links, but how do I make that happen on heroku???
I should note the app is using blade.php files
What am I missing???
This is in the /resources/views
My _htaccess inside my public folder is as follows
<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>
I tried adding RewriteBase / doesnt help.
I also tried changing htaccess to:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And my Procfile has:
web: vendor/bin/heroku-php-apache2 public/
Thanks
Well I resolved my issue, it seems that I had some lowercase letters in my web.routes path
that should have been Capital letters. Local host dosen't seem to mind if the words are uppercase or not, but linux does seem to mind.... Not sure if it will help, but i searched a long ass time for something so silly...
I had to restart my dynos for it to work, run heroku restart
Also make sure to have a Procfile in your root with
web: vendor/bin/heroku-php-apache2 public/
I resolved with:
In config/app.php
I changed for:
'asset_url' => env('ASSET_URL', 'https://appcreated.herokuapp.com'),
I'm having a problem doing internal rewrites with apache/htaccess and Laravel 5.1. The scenario is quite simple, I have some routes working on my app that needs to be rewritten to a more human/SEO/Customer friendly URL, my initial approach was simply rewrite them in htaccess as I did so many times.
However the, problem rises when I try to do it and it does not work at all, for example, if I have the url www.example.org/myroute/id and I want to rewritte to www.example.org/dummy-dummy-dummy-id.html
Normally i would do:
RewriteRule ^dummy-dummy-dummy-(\w+)\.html /myroute/$1
However when I follow this pattern with this laravel project I got a 404 error, i have been doing tests for some days and it does not matter what to do, it will always give you a 404 unless using the flag [R] wich redirects de request externally instead of the internal behaivor i need.
I have been using a dd() in the AppServiceProvider to see the details of the request the framework is getting and the URI it gets is allwas the friendly one (so the internal redirect does not reach the index.php) I have been looking at the mod_rewrite debug logs and looks like it is working fine matching the friendly url and doing and internal rewrite, but it never reaches the framework :(
this is the full htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
php_value upload_max_filesize 30M
php_value post_max_size 6M
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^local\.
RewriteCond %{HTTP_HOST} !^beta\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^dummy-dummy-dummy-(\w+)\.html /myroute/$1
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
NOTE: I know that I can implement the friendly routes straight in the routes file of laravel, but I don't understand why this is not working so I would like to find out.