No .htaccess file is working with Laravel Lumen 5.2 - .htaccess

I've tried almost every possible option with .htaccess file in my lumen's public folder but non of them are giving me Pretty URLs.
In previous versions of Lumen I hadn't touched any of the .htaccess rules and yet everything used to work perfectly with the shipped default .htaccess file.
But in this new version 5.2 nothing seems to work.
the default is as follows :
# Apache configuration file
# http://httpd.apache.org/docs/2.2/mod/quickreference.html
# Note: ".htaccess" files are an overhead for each request. This logic should
# be placed in your Apache config whenever possible.
# http://httpd.apache.org/docs/2.2/howto/htaccess.html
# Turning on the rewrite engine is necessary for the following rules and
# features. "+FollowSymLinks" must be enabled for this to work symbolically.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Any thoughts ?!

In you apache config file (httpd.conf or apache2.conf) you must change the "AllowOverride" to "All":
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>

Related

Symfony4 routing inside a subfolder

I have a symfony app in my /var/www/html/app/ and I'd like to access it via host/app/ but I can't make it work.
I have a conf file with this
<Directory /var/www/html/app>
AllowOverride All
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
</Directory>
It's commented because I tried to do the redirect here but it didn't worked so I made the following .htaccess.
And this htaccess in /var/www/html/app/.htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
With this .htaccess, When I go to ://host/app I go to the symfony app (not the apache directory structure) and that seems to be a good start.
But the problem is I'm getting an Exception No Routes found for /app/.
That's normal because /app/ is the subfolder in my server, not the start of symfony routes.
How can I make the symfony routes beginning after the /app/ folder path ?
I know there is some questions about symfony2/3 routing in subfolder but the answer requires to separate src and public files, that's not what I'd like to have.
I just want my routes working when accessing ://host/app.
For information, It works great when I access ://host/app/public/*Symfony routes*
Edit:
New app.conf
Alias /rapp "/var/www/html/app/public"
<Directory /var/www/html/app>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
#RewriteBase /app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!public/index.php)$ public/index.php$1 [L]
</IfModule>
</Directory>
I managed to resolve the problem !!!
I'm not sure the config is "proper" though but it seems to work.
Here is my working app.conf file (in /etc/apache2/sties-enabled/app.conf)
Alias /app "/var/www/html/app/public"
<Directory /var/www/html/app>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule (/public) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
</Directory>
The first RewriteRule is to prevent from internal Rewrite loop when I rewrite url like example.com/app/page-1 to example.com/app/public/index.php/page-1.
As page-1 is not a directory or a file it will loop infinitely.
So I assume as soon as I have a /public part, the rewrite worked and we stop the rewrite by doing nothing and end the rewrite with the [L] flag.
I'm not suire why I had to remove the public/ part in the "final" RewriteRule (RewriteRule ^(.*)$ index.php/$1 [L]) though.
If someone have ideas to improve this config, feel free to leave comment.
The problem is the that your web server's document root (the directory that apache will make public via the url) and your project's document root (the public directory) are not the same. Instead your server points to the project directory. That is why you have to manually go into the project's document root by adding the public/ to the url.
You should avoid making the project directory accessible as this could expose your configuration and thus make your website vulnerable, e.g. by giving people access to your database through the credentials inside the config.
You might be able to achieve your goal by storing the project somewhere else and then only symlink your project's public dir to /var/www/html/app. This will probably require some changes to your apache config, e.g. adding Options FollowSymLinks.
Another, more elaborate, approach could be using mod_proxy. The configuration will roughly look like this:
# Your public server reachable from the outside
<VirtualHost *:80>
ProxyPass /app http://127.0.0.1:8080/
</VirtualHost>
# Your internal server where the requests are proxied to
<VirtualHost 127.0.0.1:8080>
<Directory /var/www/html/app/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
...
</VirtualHost>
As you can see the internal web server points to your project's document root (public dir). You might have to do additional both in the apache setup and app, e.g. make sure trusted proxies are set correctly or adding ProxyPreserveHost On to the apache setup, but roughly this should point you in the right direction.
edit: I missed another obvious solution, using mod_alias to point your symfony app to /app:
Alias /app /var/www/html/app/public

Cakephp 2.x URL rewriting is not properly configured on your server

I think somehow most of us had a trouble with .htaccess I d'like to know if someone can help me.
Opensuse 12.3 :
Code:
Linux linux-hyo0.site 3.7.10-1.16-desktop #1 SMP PREEMPT Fri May 31 20:21:23 UTC 2013 (97c14ba) x86_64 x86_64 x86_64 GNU/Linux
I d'like to install Cakephp on my machine but I have an error on my webpage saying that "
Code:
URL rewriting is not properly configured on your server.
"
my /etc/sysconfig/apache2 file as this :
Code:
APACHE_MODULES="authz_host actions alias auth_basic authz_groupfile authn_file authz_user autoindex cgi dir include log_config mime negotiation setenvif status userdir asis imagemap php5 reqtimeout authz_default rewrite"
and the /etc/apache2/sysconfig.d/loadmodule.conf as this line at the end
Code:
LoadModule rewrite_module /usr/lib64/apache2/mod_rewrite.so
I did also change my file etc/apache2/defaul-server.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "/srv/www/htdocs">
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order Allow,Deny
Allow from all
</Directory>
Any help?
on app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and on app/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
This is quite an old question but maybe this answer is relevant for you Google users out there:
Did you change the View/Layouts/default.ctp?
This is what happens with this warning:
The warning is set in a div in View/Pages/home.ctp
In home.ctp only sets the warning when the file app/webroot/css/cake.generic.css exists
In the standard default.ctp layout, the stylesheet /css/cake.generic.css is loaded
In cake.generic.css the div with the warning is.... hidden!!!
So what happens when the default home page loads: it tries to load the cake.generic.css style sheet, which succeeds when mod_rewrite is configured correctly. So then the warning is hidden. If it fails to load the style sheet, the warning will stay visible.
This warning pops up, in short, when either there is a problem with mod_rewrite and htaccess, or you changed the layout so that the cake.generic.css is no longer loaded...
First check if you even try to load the stylesheet. Does it show up in your F12 console?
After hours trying to track down the problem I finally found that my .htaccess file never existed in the first place. I copied the following code into a new .htaccess file and hey presto.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Let me first say: I HATE CAKEPHP!!!!
I just spent hours working on this issue.
I learned that cake tests URL rewrite by checking for app/webroot/css/cake.generic.css
Make sure that exists.
My solution came after I checked the apache error_log and saw it complaining about not being able to find http:/myproject/css. Well, there is no css directory there by default. I created a link (ln -s app/webroot/css) and it solved Cake's problem.
If you got this error after new installation of Cakephp and you do not changed any of the files(css files or cake.generic.css) then do the following:
sudo a2enmod rewrite
sudo service apache2 restart
sudo nano /etc/apache2/sites-available/000-default.conf
Look for “DocumentRoot /var/www/html” and add the following lines directly below:
AllowOverride All
sudo service apache2 restart
Make sure you change all AllowOverride None to AllowOverride All
I have this problem and solve this copying the lines of cakebook:
http://book.cakephp.org/2.0/en/installation/url-rewriting.html
There is also a .htaccess file in the root folder, i.e. /.htaccess. This may not have been copied across as it's hidden by default by most operating systems.
Try adding this as the contents of /.htaccess and checking it makes it to the web server.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
There's more explanation at http://book.cakephp.org/2.0/en/installation/url-rewriting.html
There’s two solutions:
1) Either set the DocumentRoot in your Apache configuration file to the app/webroot/ directory, and CakePHP will use the .htaccess file there.
2) Place a .htaccess file in the root of your application, as by default I don’t think one gets created if you use the CakePHP console to generate an app. That .htaccess file should look this this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Codeigniter doesn't work without index.php

I'm using MAMP with alias named works.
Codeigniter is at localhost/works/project/web
controllers doesn't work without index.php before them (localhost/works/project/web/index.php/auth/register)
$config['base_url'] = 'localhost/works/project/web/'; //with http://
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
(I tried all of them for uri_protocol)
I created and edit .htaccess file at /User/me/works/project/web/
I tired all the .htaccess files about this issue.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Users/me/works/project/web
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#‘system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don’t have mod_rewrite installed, all 404’s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
creates error, which is:
[error] [client ::1] File does not exist: /Users/me/works/project/web/auth
it is same when I use RewriteBase /
mod_rewrite is active in phpInfo.
I couldn't find the solution.
Your RewriteBase is wrong. It should not be the relative file path for your server, it should be the relative URL path for your rewrite rules and such. More info here.
If you've ever used HTML's <base> tag, it's pretty much the same principle. If your main localhost URL is http://localhost, and your project is in the subfolder http://localhost/my-project, then you would use RewriteBase /my-project/.
If you didn't use RewriteBase, and your project is in a subfolder, you'd have to add the subfolder to every one of your URLs and rewrites, like this:
RewriteRule ^(.*)$ /my-project/index.php/$1 [L]
Food for thought:
Start your .htaccess files as simple as possible. The more you throw at it right away, the more that can go wrong, and the harder it is to debug. Especially if you're a noob to .htaccess files. Don't blindly copy and paste -- figure out what things actually do.
The system folder access part is redundant now -- the system folder has its own .htaccess to restrict requests, just like the application folder.
1.Make below changes in application/config.php file
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.use this in .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and enable rewrite mode using below command
a2enmod rewrite
and Edit the file /etc/apache2/sites-enabled/000-default
change the AllowOverride None to AllowOverride All.
and finally Restart your server
You certainly don't have mod_rewrite on or you did not install it with MAMP
Open your httpd config file and change
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
To
AllowOverride All
uncomment this line:
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Also make some changes to users here: /etc/apache2/users/username.conf
LoadModule php5_module libexec/apache2/libphp5.so
DocumentRoot "/Users/username/where/ever/you/like"
<Directory "/Users/username/where/ever/you/like">
Options Indexes MultiViews +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Get more info here http://adam.merrifield.ca/2010/08/09/apache-mod_rewrite-php-and-os-x-10-6-snow-leopard/
Restart MAMP
To find out if mod_rewrite is on, follow this answer in Stackoverflow:
How to check if mod_rewrite is enabled in php?
Just to be sure your .htaccess is not the issue, could you try this one. It's been tested:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /Users/me/works/project/web/
# If the start of the URL doesn't match one of these...
RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|themes|uploads|css|images|js)
# Route through index.php
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Access to certain folders are granted above and the rewritebase has a trailing slash.
Make sure you have any other nested .htaccess overriding this very one.
I fixed the problem by instead of using .htacces, I write them to httpd.conf.
I checked the AllowOverride is All but I'm not sure why .htaccess isn't working. Because of I lost too much time with this issue, I'm going to use this way.
Thanks for the answers.
Use AllowOverride All on your vhost:
<Directory "/path/to/your/site">
....
AllowOverride All
</Directory>
Open your httpd config file
LoadModule rewrite_module modules/mod_rewrite.so then AllowOverride All
<Directory "C:/xampp/htdocs"> //example for xampp
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I have installed codeigniter in a url like the format: http://11.12.34.45/~project/
I tried different suggestions and finally this following url provided the solution:
https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html
You need to change two files of Apache,
httpd.conf
httpd-vhosts.conf
change this in httpd.conf
<Files ".ht*">
Require all denied
</Files>
to,
<Files ".ht*">
Require all granted
</Files>
and add below code in httpd-vhosts.conf,
<VirtualHost *:8000>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Allow from all
</Directory>
</VirtualHost>

Htaccess basic help needed

I'm trying to install friendica on my webhost (hourb, similar to 000webhost but with ssh).
I'm installing it to a directory/subdomain imoppen.domain.com (domain.com/imoppen)
But it says: Url rewrite in .htaccess is not working. Check your server configuration.
and i can't continue the installation.
I think it's something that has to do with directory's with the rewritebase part, but i don't know how to fix it.
It also gives a error in php, but that is not a very big deal for me;
Warning: set_time_limit() has been disabled for security reasons in /home/username/public_html/imoppen/boot.php on line 290
My first .htaccess (domain.com) contains:
# DO NOT REMOVE THIS LINE AND THE LINES BELOW ERRORPAGEID:yLaNyW
ErrorDocument 404 /404.html
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE yLaNyW:ERRORPAGEID
RewriteBase /
My second .htaccess (domain.com/installationdirectory) contains:
Options -Indexes
AddType application/x-java-archive .jar
AddType audio/ogg .oga
<FilesMatch "\.(out|log)$">
Deny from all
</FilesMatch>
SetEnv PHP_VER 5_3
<IfModule mod_rewrite.c>
RewriteEngine on
# Protect repository directory from browsing
RewriteRule "(^|/)\.git" - [F]
# Rewrite current-style URLs of the form 'index.php?q=x'.
# Also place auth information into REMOTE_USER for sites running
# in CGI mode.
# If you have troubles or use VirtualDocumentRoot
# uncomment this and set it to the path where your friendica installation is
# i.e.:
# Friendica url: http://some.example.com
# RewriteBase /
# Friendica url: http://some.example.com/friendica
# RewriteBase /imoppen/
#
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
</IfModule>
As you can see I've tried to use the rewritebase part, which unfortunately did not work.
My overall php version is set to 5.3
It seems like you are on hourb hosting (so am I) I solved it by going to settings -> htaccess -> Allow URL rewriting

FreeBSD Server .htaccess issues

Server Details:
FreeBSD
PHP Version 4.3.11
Apache
Appache Modules:
mod_throttle, mod_php4, mod_speedycgi, mod_ssl, mod_setenvif, mod_so, mod_unique_id, mod_headers, mod_expires, mod_auth_db, mod_auth_anon, mod_auth, mod_access, mod_rewrite, mod_alias, mod_actions, mod_cgi, mod_dir, mod_autoindex, mod_include, mod_info, mod_status, mod_negotiation, mod_mime, mod_mime_magic, mod_log_config, mod_define, mod_env, mod_vhost_alias, mod_mmap_static, http_core
The issue I am having is when ever I write any kind of code in the .htaccess file, it throws a 500 Internal error
I am simply trying to rewrite url's and am using the exact code that wordpress creates for me and even tried custom code used before on previous servers and it still does not work.
WordPress created code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /lobster-tail-blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /lobster-tail-blog/index.php [L]
</IfModule>
# END WordPress
And even a simple thing like this throws the error:
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
Anyone know of any fixes or why this is causing this error? I have the mod_rewrite module loaded
You should take a look at AllowOverride it is probably turned off try something like this:
<Directory /path/to/www/root/>
AllowOverride All
</Directory>

Resources