How to remove http://IP_ASDRESS/index.php/xyz from laravel 5? - apache

I know that question has been answered number of times, but I would like to tell you what I did but still I haven't manage to remove it.
Firstly I'm hosting my app on digital ocean with apache 2, and I double check that the mod_rewrite is activated. Also I add on my htaccess in the public folder the following
<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]
on the index.php I have the following lines
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
$app->run();
After doing this configurations I couldn't remove the index.php/xyz.
I would like to ask if I'm doing something wrong or if I'm missing something.
Ps. the http://IP_ADDRESS is working fine with the home page.
PSS. I restart the apache 2 serval times.

Related

After pushing my site on shared hosting blank page

I would like to completely reshuffle my site without interrupting its availability.
I use a shared hosting. On my domain, I created several subdomains one hosts the currently available site, the other is reserved for my reshuffling.
The root documents of the sites are respectively:
subdomain1.domain.fr/public
subdomain2.domain.fr/public
I am using the same .htaccess files on both subdomains.
The first one works. The second displays a blank page
On firefox there is no additional information.
On Brave or Google chrome an error 500 message is displayed.
Here is my .htaccess
<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]
</IfModule>
And here are some useful values in .env
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost
Thank you for help
Additional EDIT
when replacing the content of index.php with only phpinfo(); it display the page php info correctly.
Eventually, using
phpinfo(); exit;
in the index.php file and moving them statement after statement, I found that the vendor/autoload.php was missing.
And as who can do the most can do the least, I added the full vendor directory, Probably it is not necessary.

Redirect subfolder to the main domain (root) using mod_rewrite (htaccess)

So I bought a script from the other guy (nothing fancy, let's say just a customized CMS) which is kinda complicated and uses frameworks that I don't know nothing about except names like "bootstrap", "laravel" and so. I am the guy who knows the basis and know some things from intermediate level but again, only some so when I see some fancy solutions I am getting confused.
Like here - I have never seen page built on files with strange extensions and two .htaccess files - one in root, and second in /public/ folder. Still, even though there are so many files, everything works really fine and fast.
Here is the issue's description:
So it seems that when browser loads the page (domain.com), it requests (I guess) content from /public/ folder and everything works fine and domain remains as domain.com. The thing is, that domain.com/public also works and I want to create redirection on this specific address just to prevent indexing this crappy-looking address of domain.com/public but bearing in mind, that domain.com should still work fine.
I have tried maaany solutions found here on SO and on other pages but they resulted in either crashing page (internal server error) or not doing anything at all. I think some of them might work but only when files are not embedded in another sub-folder. Eh I don't know, I am out of ideas. Can you please help me?
Here is the root's .httaccess
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
And here is the public/.htaccess
<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]
</IfModule>
It looks to me like what you have should work, specifically the first condition + rule in the root .htaccess is meant to do what you're asking. I would polish it up a little:
In /.htaccess:
RewriteEngine On
RewriteBase /
# Fix URLs that begin with "public" subdirectory
RewriteCond %{THE_REQUEST} \s/public(?:/(\S*))?\s
RewriteRule ^ %1 [NS,NE,R=301,END]
# Internally rewrite everything else
RewriteRule ^(?!public/).* public/$0 [DPI,L]
In /public/.htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Pretend this is the root
RewriteBase /
# Redirect trailing slashes if not a folder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [DPI,R=301,END]
# Handle front controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!index\.php$). index.php [DPI,END]
</IfModule>
You can use L instead of END if your version of Apache is old, you'll know because of a 500 error.

Remove htaccess action to public directories

How I can disable the rewrite rule to access directories into Laravel public directory, without affecting my Laravel project?
ex: I have (asd) directory into my public Laravel but I can't access
if I remove
RewriteRule ^ index.php [L]
line and I can access, but this affects my Laravel project.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This line is doing exactly what you're asking for (which is to apply the rule on anything except real directories):
RewriteCond %{REQUEST_FILENAME} !-d
However, you seem to have an issue with your rewriting.
Did you take a look at your access logs within your web server ?

Object not found! in xampp

I'm using creo's module system and laravel 4. mod_rewrite is enabled and I have a .htaccess I'm also using XAMPP. The weird thing is, if I use MAMP then it works fine but if I use XAMPP that is when I get the Object Not Found error. I would like to use XAMPP because it is much more easier to create a virtual host with it then it is with MAMP.
In my url I have
http://localhost/test-modules/index.php/admin/content
but I need it to be
http://localhost/test-modules/admin/content
here is my .htaccess
Order allow,deny
Allow from all
<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]
# Disallow access to following directories
#RewriteRule ^vendor($|/|/.*|./*) – [L,R=404]
#RewriteRule ^app($|/|/*|/.*) – [L,R=404]
</IfModule>
Do yourself a favor and don't use either MAMP or XAMP. Use homestead.
http://laravel.com/docs/4.2/homestead
To give you some guides:
https://laracasts.com/lessons/say-hello-to-laravel-homestead-two

Having trouble with mod_rewrite on my Laravel app

Currently, I can only access links on my Laravel project if they are in the form of domain.com/index.php/somepage. I want to be able to be able to get access with a URL like domain.com/somepage. On my local Windows machine it is working fine. My server is on Ubuntu and running Apache 2.4.6 and the rewrite module was enabled via a2enmod rewrite. My .htaccess is the default one that ships with Laravel:
<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've also tried the alternate in the Laravel docs both with and without the <IfModule>:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I realize this has been asked before but I still can seem to get it working with other examples that I've seen. I'm guessing it must be some Apache configuration that I don't have set.
Did you make sure that allowoverides all was in your httpd config?
That sounds like your issue.