I have done my project using laravel. I want to upload my project on 1and1. I set my directory structure on 1and1 is as '/directory' which contains index.html file which links to the other page in /directory/EngageV1/public/auth/login. but when I visits this page I am getting the error page as,
Multiple Choices
The document name you requested (/index.php) could not be found on this server. However, we found documents with names similar to the one you requested.
Available documents:
/index.html (common basename)
Please consider informing the owner of the referring page about the broken link.
My .htaccess file looks like,
<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>
If enter url as /directory/EngageV1/public/ then it shows me the welcome page which I have set in routes.php file for route as '/'. Only this page works fine,I don't know what to do, Please give any suggestion.
Replace default contents in your .htaccess file under your the public
folder with the following.
RewriteBase /
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
If you still have problems look at this tutorial about how to deploy a Laravel webapp to 1and1
I know this is is an very old topic, but it took us some time today to find out what's going wrong on an old 1and1 (now Ionos) server. Turned out, the "multiple choices" page doesn't com from Option +MultiViews / mod_negotiation, but from a module called mod_speling that's running there by default. You can disable it in the .htaccess file:
<IfModule mod_speling.c>
CheckSpelling off
</IfModule>
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 am trying to implement SEO friendly URLs using .htaccess and PHP.
I have achieved 90% of my goal and struggling with just one use case.
Here is what happing, when I access the following url
http://somesite.com/cms/movies/tarzan
it lands on
my-handler.php?the_url=movies/tarzan
This is perfect and that is what I want because then I manage it myself. The real problem is when I don't provide any slugs, then it lists the directory (means show all files and folders in it)
http://somesite.com/cms/
Can someone please help me fix following .htaccess content, so that even if I don't provide slug it should still be handled by my-handler.php instead of lisiting full directory?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/
RewriteCond %{REQUEST_FILENAME} !/(admin|css|fonts|ico|include|js)/
RewriteRule ^my-handler\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/my-handler.php?the_url=$1 [L,QSA]
</IfModule>
Solved
As per #Roman suggestion, I added the following to the above listing and it solved my problem. Plus I do not have to compromise on accessing physical directories RewriteCond %{REQUEST_FILENAME} !-d
DirectoryIndex my-handler.php
At first you have to set the DirectoryIndex to handle every request which points to / with your my-handler.php. This can be done by adding the line to your .htaccess
DirectoryIndex my-handler.php
To disable the directory listing, you have to forbid the listing by adding the following line to your .htaccess
Options -Indexes
Remember that this configuration is per .htaccess and just for the directory you are placing the file in. If you want to make changes for your whole webserver, you can edit the httpd.conf and search for
Options Indexes
and remove the Indexes option.
Documentation
The listing is provided by the mod_autoindex module.
Nice side-fact
If you just want to disable the listing of specific file-types like .env or .php files, you can add the option IndexIgnore *.php to you .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/
RewriteCond %{REQUEST_FILENAME} !/(admin|css|fonts|ico|include|js)/
RewriteRule ^my-handler\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css|json|woff|ttf)
RewriteRule ^(.*)$ /cms/my-handler.php?the_url=$1 [L,QSA]
</IfModule>
I have a food blog website, with many posts stored in a database. When someone clicks on a link to a post, the website searches the database for the post and presents it in a template. I don't store an HTML file for each post.
Right now, I do it by handling a 404 error (which goes off because the requested HTML file doesn't exist) and searching the database from there. I know this isn't right.
How can I set up my web server (Apache running on a Raspberry Pi), so that all requests go to one page, which will do the searching and send the user to the right page? And is this the right thing to do?
You can do that with a file you put in your website root named .htaccess and using the mod_rewrite module. You'll need to make sure .htaccess and mod_rewrite are enabled in the Apache configuration. But once enabled you can do something like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
That will rewrite any URL that doesn't refer to an actual existing file or directory to your index.php which you can use to handle the request.
For example, if someone visits http://yourdomain.com/article, the path will be internally rewritten to index.php?path=article and you can access the path using $_GET['path'].
Note: If you want to literally serve everything through that single entry point you could remove the two middle lines and that would send everything through there. Including images, scripts, CSS etc, which is generally not what you want.
You need proper .htaccess rules in your public root directory and you need a apache2 mod_rewrite module enabled.
On Ubuntu you can can enable it with the following command:
sudo a2enmod rewrite
your .htaccess file could look like the following:
<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>
In the past, I have got this working no problems at all, but for some reason on my new server I just can't get it to work.
I have the following .htaccess file in the root of my application
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have also enabled mod_rewrite and have confirmed this with php_info()
my site is located at /var/www/html/test
Is it possible that although mod_rewrite is enabled that it is not working and if so, how can I test it?
On some server implementations, you'll need to wrap it within <IfModule> tags.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Also check your httpd.conf file to ensure it has:
Options FollowSymLinks
AllowOverride All
It'd also be worth checking to makesure the .htaccess file isn't being overridden by another .htaccess file.
A simple way to test if .htaccess is working
Simply put the following in your .htaccess file:
deny from All
What this does is deny access to your site from everyone. If you are presented with a 403 forbidden when trying to access the site - the .htaccess file is being included. If not - see above.
I use this on my codeigniter setup
RewriteEngine on
# prevent these directories from hitting CI
RewriteCond $1 !^(index\.php|images|assets|robots\.txt|crossdomain\.xml)
# route everything else to the index.php
RewriteRule ^/(.*)$ /index.php/$1 [QSA]
(my setup is done in the virtualhost of .conf and not in .htaccess, though they are usually about the same configuration)
I have a website with this in the .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?menu=$1 [L,QSA]
#DirectoryIndex index.php
My problem is even, if I change a single letter the website is rendering a 500 Error. Even if I empty complete file, it still shows me the 500 Error.
What I want to do is, there is a page like this on the domain
http://www.example.co.uk/brochure/generate.php
The file generate.php does exist in /brochure/ directory.
But still the generate.php does not load and it is loading the index.php file.
Any help?
Try the following which I know should work:
<IfModule mod_rewrite.c>
#Turn the Rewrite Engine ON
RewriteEngine On
#Set the base where to rewrite the requests
RewriteBase /
#Allow direct file access
RewriteCond %{REQUEST_FILENAME} !-f
#Allow direct directory access
RewriteCond %{REQUEST_FILENAME} !-d
#Disallow certain files.
RewriteCond %{REQUEST_FILENAME} !brochure\/generate\.php$
#Rewrite URLS To GET[menu] and make sure this is the last rule.
RewriteRule ^(.*)$ index.php?menu=$1 [L]
</IfModule>
if you do not see any rewriting taking palce then check to see the module for rewrite is installed.
If an empty file triggers a 500 status code as well, then the error is somewhere else: you are not editing the real .htaccess file being used by Apache, the error comes from the application, etc.
In any case, you should find the error log: that's where the exact details are shown. In Linux, it's normally under /var/log/httpd. In Windows, it can be under %ProgramFiles%\Apache Software Foundation\Apache2.2\logs. If it's a shared hosting account, you'll probably have an "Errors" or "Logs" feature in your control panel.