URL Rewriting issue (Apache2 / Debian 10) - apache

I got a basic problem that I can't resolve.
I set up a LAMP server on a Debian 10 machine which run into a Docker container.
PHP and the services Apache and MySQL are functionnal, but I got a problem with the URL rewriting.
It don't run, even on the basic entry point of my web server which is : "http://localhost/"
If I use the real adress, It work, but if I brink a "virtual" adress like "http://localhost/toto" for exemple, I got a 404 error from Apache.
Here is the content of my .htaccess file that I put on the root of my base directory "/var/www/html" :
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !/index.php$
RewriteCond %{REQUEST_URI} !(.css|.js|.jpg|.jpeg|.png|.svg|.ttf|.woff|.woff2|.pdf|.zip|.mp4|.avi|.ogg)$
RewriteRule .* /index.php
In the configuration file of my default website (/etc/apache2/sites-available/000-default.conf), I've the directive "DocumentRoot /var/www/html".
If I do a phpinfo(), I see the "mod_rewrite" in the loaded_module.
Is anybody know how can I solve it ?
Mickaël

Finally..., It's OK !
My .htacess file was just ignored by Apache, because the AllowOverride statement was set to "None" by default in my "apache2.conf".
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
I changed it by "AllowOverride All", I restarded Apache and I could valid that the rewriting work fine.

Related

.htaccess not working on SSL apache

Trying to fix this .htaccess, so it can work on a SSL apache server. Before it was hosted on another Linux server (http://) and was working without problems, but when uploading the files to another Linux server with apache and SSL (https://), it stopped working. The main function is to hide the .php extension...
Here´s what I was using:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
Thanks for your help!
So, .htaccess files may not be allowed, and by default on many systems they are not allowed. To see if .htaccess is allowed, make this your .htaccess:
BREAK IT!
That should be the only contents in your .htaccess. Attempt to load any page on your website, and if .htaccess usage is enabled, you would see "Internal Server Error" or possibly some other error, but you would not see your actual page.
If you do see the error, that's actually good and means .htaccess usage is enabled. If you don't see the error, it's likely that you will have to find your Apache .conf file and inside look for the line(s):
AllowOverride None
Change that to:
AllowOverride All
If after doing that you still can't use .htaccess, then there may be other apache related files that have "AllowOverride None". On that comes to mind is your virtual host file, and on my system that is located at /etc/apache2/sites-available/.
If you still have problems, check this out:
https://docs.bolt.cm/3.3/howto/making-sure-htaccess-works
Solution is for the issue, need to change in apache2.conf file after that it will works,
Change this file /etc/apache2/apache2.conf
update it same
OLD:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
New Updated Code:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I had a similar problem. Apache 2.4.23 with .htaccess error 404 set up.
Using it with HTTP works fine; access it with HTTPS didn't work.
I seted AllowOverride All in the http.conf and error 404 wors well.

All URLs redirect to mod_rewrite error page

I have a few platforms (domain.com/omeka, domain.com/wordpress, domain.com/omeka-s) living alongside each other on an Azure cloud server running Ubuntu 14.04.4 and Apache 2.4. A few days ago, I tried installing an additional platform, but doing so seemed to break everything else on the server, so I removed it and reinstalled Apache. After editing the .htaccess file to remove a typo, everything worked. I left for the weekend, came back to work this morning, and everything is broken again.
By broken, I mean every URL on the server redirects to a mod_rewrite installation error page for Omeka (domain.com/install). Omeka has already been installed and running for months. MR needs to be enabled for Omeka to be installed and function properly. MR is definitely enabled.
$ sudo a2enmod rewrite
Module rewrite already enabled
I'm assuming this is a problem with either the /var/www/.htaccess file or the /etc/apache2/apache2.conf file. Here's the relevant .htaccess code that is default for Omeka:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule !\.php$ - [C]
RewriteRule .* - [L]
RewriteRule ^install/.*$ install/install.php [L]
RewriteRule ^admin/.*$ admin/index.php [L]
RewriteRule .* index.php
And here's the relevant(?) apache2.conf code:
<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
AccessFileName .htaccess
If I remove the .htaccess file, or if I just remove some of RewriteRules, everything on the server is inaccessible (including Wordpress & Omeka-S). I'm clearly missing something. Any ideas?
Figured out the problem. Very simple, stupid stuff.
Problem 1: When I reinstalled Apache, the /etc/apache2/sites-available/000-default.conf file reverted the DocumentRoot to /var/www, when it was supposed to be /var/www/html.
Problem 2: There was an additional and nearly identical .htaccess file in /var/www/html/omeka that had a typo. It was missing the ^ before install/.*$
Also, the IT department who set up the cloud server for me installed 2 instances of Omeka (who knows why), one under /var/www and one under /var/www/html, so this whole problem most likely would have been averted (or at least easier to solve) if that wasn't the case.

How to use DAV and DirectoryIndex in Apache 2.4?

In my apache configuration I have a virtual host configured like this:
Alias /mediamanager /storage/files/mediamanager
<Directory /storage/files/mediamanager>
DirectoryIndex /mediaManagerIndex.php
DAV On
# ... And some authentication directives ... #
</Directory>
The idea is that someone can access the files both by a WebDAV-Client and also a simple web browser in which case some pretty directory view is generated by a PHP script.
That worked great in Apache 2.2, but recently I upgraded to Apache 2.4 and now it is broken. I highly suspect I I suffer from this bug which is already 2 years old and no fix in sight. The proposed workaround to add:
<Limit PROPFIND>
DirectoryIndex never-encounterable-file-name.html
</Limit>
Does not work for me. Probably because I still want to have a directory index. If I remove my DirectoryIndex altogether WebDAV works again (no index.html or similar files exists in this directory) but of course I loose the ability to use my PHP file as directory index. I tried to specify my DirectoryIndex in a <Limit GET> but this had no effect.
Is there any way to get both DAV and DirectoryIndex to work simultaneously in Apache 2.4 on Debian (if anyhow possible without changing the source code and recompiling)?
In order to fix this, disable directory indexing for the WebDAV site.
In your sites-available/site.conf file add DirectoryIndex disabled to the <Directory> declaration, like so:
<Directory /path/to/my/webdav/dir>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
DirectoryIndex disabled
</Directory>
Then just reload Apache and you will no longer have that issue:
sudo service apache2 reload
For me, the following configuration solved both problems:
WebDAV works again
directory indexing, if the user uses a web browser to access the repository
It works by manually implementing the directory-indexing feature with simple rewrite rules, which are applied only for the GET request method.
The following code has to be placed inside the server config or virtual host context in the apache configuration file.
# Turn off (automatic) Directory-Indexing
DirectoryIndex disabled
RewriteEngine On
# Rewrite rules for the root directory
RewriteCond "%{REQUEST_METHOD}" "(GET)"
RewriteRule "^/$" "/index.php" [L]
# Rewrite rules for other sub-directories
RewriteCond "%{REQUEST_METHOD}" "(GET)"
# The following line checks, if the index.php file exists
RewriteCond "%{DOCUMENT_ROOT}/$1/index.php" "-f"
RewriteRule "^/(.*)/$" "/$1/index.php" [L]
Don't forget to reload Apache!
This is the solution I am currently using, located in a .htaccess file at the root of the directory tree used by the WebDav service. In this case I do not use PHP, only html files, but it can be easily adapted:
# Turn off automatic directory indexing
Options -Indexes
DirectoryIndex disabled
# Redirect directory requests to index.html, only for GET requests
RewriteEngine On
RewriteCond %{REQUEST_METHOD} "GET"
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1index.html [L]
In order to launch always the requested PHP file, just replace "index.html" on the last line by the PHP file name:
RewriteRule ^(.*)$ $1mediaManagerIndex.php [L]

Codeigniter application index.php removed randomly in url on amazon EC2 clound server

I am working on a web application. I am facing a very strange issue while navigating the app on cloud amazon EC2 instance 1 that it randomly choose some links and when I click on those links it is redirecting me to page not found or sometime home page or sometime on login page. Although session still persist.
Previously I have added the .htaccess file to removed the index.php from the urls but after noticing this issue I have revert the changes but my re_write_mode still enabled in apache httpd.conf file and .htaccess file reside on root of the application with commented code.
Apache configuration mentioned below.
DocumentRoot "/var/www/html"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Not sure why you would be running in that problem from what you posted...here is the .htaccess file I use at the root of all of my CI projects to remove index.php from the URL
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/
RewriteBase /
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
Nothing looks extremely out of the ordinary regarding your apache config. I would say that it sounds more like a problem with your "routes." Do you have any custom routes setup in your app?
Also, did you change your $config['index_page'] and/or $config['base_url'] in your config file?

Redirect Using htaccess

I am trying to redirect /folder to / using .htaccess but all am I getting is the Apache HTTP Server Test Page.
My root directory looks like this:
/
.htaccess
-/folder
-/folder2
-/folder3
My .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule ^(.*)$ folder/$1 [L]
What am I doing wrong? I checked my httpd.conf (I'm running Centos 5.3) and the mod_rewrite library is being loaded. As a side note, my server is not a www server, its simply a virtual machine so its hostname is centosvm.
Addition: I have found that the mod_rewrite module is loaded, but none of my .htaccess redirects seem to be working.
Addition: My httpd.conf directory directive looks like:
<Directory />
Options FollowSymLinks
#AllowOverride None
</Directory>
What does you AllowOverride say? (see: http://httpd.apache.org/docs/2.0/howto/htaccess.html)
And that would bring us to requiring this in (virtual)host/directory settings:
AllowOverride FileInfo