.htaccess not working on apache24 - apache

I am trying to rewrite the url for a rest call (backend written in php).
The problem is, that the .htaccess file is not working, or the file in general is ignored by the server.
What i've tried
I've edited the httpd.conf file and changend following lines:
<Directory />
Options All
AllowOverride All
</Directory>
<Directory "${SRVROOT}/htdocs">
Options All
AllowOverride All
Require all granted
</Directory>
i also added a Directory Tag for my specific folder:
<Directory "${SRVROOT}/htdocs/my/path/backend/">
Options All
AllowOverride All
</Directory>
My .htaccess file looks like this:
#.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php/$1 [L,QSA]
Because i am using the RewriteEngine i had to enable this module in the httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
Infos
I'm working on Windows 10 machine.
My Apache version is: 2.4.16 Win32
Problem
The problem is that the server ignores the .htaccess file. I know that because i tried to change the DefaultIndex with following line:
DirectoryIndex startPage.html
without any success.

Related

Apache server .htaccess file won't load at all

I know, there are thousands of .htaccess topics out there but I'm looking for days now and can't find an answer.
I want to use .htaccess to redirect from e.g. https://myserver.com/project/about to https://myserver.com/project/about.php using mod_rewrite.
Project structure
in my /var/www/project folder there is
an about.html containing nothing more than a simple <h1> Header
a .htaccess file containing
RewriteEngine on
RewriteRule ^about$ about.html [NC]
I can access the file with https://myserver.com/project/about.php.
What I've tried so far
I've looked at my /etc/apache2 folder (I'm running an ubuntu server, apache v. 2.2.22).
In the internet I've found I should add AllowOverwrite All somewhere but I couldn't find out where. I've found alot of places where it should go in the internet and tried most of them - without success.
Somehow my files all differ from others.
I've also tried to write in the first line of my /var/www/project/.htaccess deny from all or just random things to see if an error 500 gets printed. Nope. No feedback from my .htaccess at all.
Files
/etc/apache2/..
apache2.conf: Containing no <Directory> tag.
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy all
</Files>
httpd.conf: Empty.
conf-available/php5.6-fpm.conf: Containing no <Directory> tag.
sites-available/default: Empty.
sites-enabled/default.conf:
<VirtualHost *:80>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>
sites-enabled/ssl.conf:
<VirtualHost *:443>
...
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
...
</VirtualHost>
I hope you can help me because I literally have no single idea anymore.

Not able to access laravel routes in apache2 server

I've deployed a new laravel installation to my server, While doing so I configured my apache2 as following:
I added 000-default.conf file in /etc/apache2/sites-available/ as following:
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
I've my laravel installed into /var/www/html/stellar folder now I access my installation through:
http://52.39.175.55/stellar/public/
But while calling the routes it is not working, Like
http://52.39.175.55/stellar/public/oauth/token
Here is the screenshot:
But suppose I call through this:
http://52.39.175.55/stellar/public/index.php/oauth/token
I get the access,
I tried changing my public/.htaccess file to something like this:
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /stellar
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
Still there is no change, Help me out in this.
Your VirtualHost on /etc/apache2/sites-available/ should look like this:
<VirtualHost *:80>
DocumentRoot "/var/www/html/stellar/public"
ServerName yourdomain.com
<Directory /var/www/html/stellar/public>
AllowOverride All
</Directory>
</VirtualHost>
Then restart apache2 and it should work.
I hardly recommend you to duplicate the 000-default.conf file, rename it and include the VirtualHost, then enable it with a2ensite command, just because it's more easy to manage.

.htaccess file on the localhost

I am trying rewrite my url by .htaccess file. I tried to find out solution before I ask but nothing to seem work. Could you please help out? Thank you.
Here is my .htaccess file (In the root folders):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
RewriteRule ^film/([^/]*)/([^/]*)\.html$ /html/movie/film.php?film=$1&genreID=$2 [L,QSA]
</IfModule>
I did set these lines (in etc/apache2/sites-available/ 000-default.conf):
DocumentRoot /var/www
<Directory "/var/www/html/movie">
AllowOverride All
</Directory>
I am using Linux mate Apache 2.4.7 and in error.log is nothing wrong.
Do you allow mod_rewrite in php.ini?
You have an .htaccess in the document root folder, which is /var/www according to 000-default.conf.
But you don't allow .htaccess files in /var/www. You allow .htaccess files in /var/www/html/movie, again according to 000-default.conf.
To allow .htaccess files in /var/www or /var/www/html, you must say so, e.g.
<Directory /var/www>
AllowOverride All
</Directory>
or
<Directory /var/www/html>
AllowOverride All
</Directory>
N.B. you don't need AllowOverride All, AllowOverride FileInfo is sufficient for using mod_rewrite, see AllowOverride

Laravel Routes not working, Apache configuration only allows for public/index.php/route

Example:
Route::get('/get', function() {
return 'get';
});
To view the route above, I must navigate to public/index.php/get.
I've viewed quite a few SO posts and googled around trying different things and it hasn't made a difference (yes I restart apache every time).
Here is my .htaccess in the public directory:
<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>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
What could be causing this still? I'm running Ubuntu.
Two most common causes of this behavior are:
mod_rewrite not enabled
sudo a2enmod rewrite && sudo service apache2 restart
AllowOverride is set to None, set it to All, assuming Apache2.4
sudo nano /etc/apache2/apache2.conf
search for <Directory /var/www/> and change AllowOverride None to AllowOverride All, then save the file and restart apache
Do you have mod_rewrite installed and enabled on apache? Try to remove the if lines ( and ) and see if it throws an error when you try to load the website. If it does, run sudo a2enmod rewrite and restart apache.
This is the .htaccess I have on my public/ directory:
<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>
In the Apache Configuration file may be located at /etc/httpd/conf/httpd.conf (location and names varies on server), provide AllowOverride permission for .htaccess file by updating the directory as follows:
<Directory "/var/www/laravel-sample-project/public">
AllowOverride All
</Directory>
This may solve your problem on laravel routes.
Also ensure that you're providing access "AllowOverride All" limited to directories, such as mentioned above and limited to the directory /var/www/laravel-sample-project/public (mentioned here is the root directory for my project which may varies for you)
Changing AllowOverride None to AllowOverride All and sudo a2enmod rewrite && sudo /etc/init.d/apache2 reload did help.
I know it's an old question, but for people coming from search engines:
Although the apache site config I had enabled (/etc/apache2/sites-enabled/sitename.conf) had AllowOverride All
But for some reason the /etc/apache2/apache2.conf file had AllowOverride None for /var/www/ directory.
Solution:
Run nano /etc/apache2/apache2.conf
Find Directory /var/www/ (on mac you can ctrl+w, paste the text and hit enter)
Inside it, change AllowOverride None to AllowOverride All
So, this
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
becomes this:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
If you do not use a .htaccess file, you need to specify the directory for your redirections:
<IfModule mod_rewrite.c>
RewriteEngine On
<Directory /home/vitela/laravel/public>
RewriteBase /public
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L,QSA]
</Directory>
</IfModule>
In MacOs. The Main problem of .htaccess not working is there is not mod_rewrite.so enabled in httpd.conf file of apache configuration.
i have solved this by uncomment the line :
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Remove the # from above line httpdf.conf. Then it will works. enjoy!

This script is only accessible from localhost

I have a working project with Symfony2.
One of my bundles works well by default but when I activate mod_rewrite I get
This script is only accessible from localhost
This happens only with the routes configured on this bundle, others work fine with mod_rewrite
Here is my vhost config
<VirtualHost *:80>
ServerName my_application.my_domain.net
ServerAdmin xxx#xxx.xxx
DocumentRoot "/var/www/my_application/web"
<Directory /var/www/my_application/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from All
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
Where can that come from ?
Update
Example
I'm getting the error when trying to access
my_application.my_domain.net/config/list/produit
If I disable mod_rewrite I can access
my_application.my_domain.net/app.php/config/list/produit
Are you hitting app_dev.php or config.php?
By default, both of those restrict connections from anywhere but localhost and display that exact same message.
Update
After the update, I think the problem may be because you have MultiViews enabled. MultiViews can try to load config.php even if it is just referenced as config. Try removing that and see if it helps improve anything.