Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Clean-Urls with MultiViews enabled

I'm trying to allow Clean-Urls, having MultiViews enabled.

All the pages I have, are in the root folder itself.

I am trying to achieve the following :

(current-status -> what I am trying to achieve)

 1. foo.com/services.php -> foo.com/services
 2. foo.com/services == foo.com/services/
 3. foo.com/services.php/second-level/ == foo.com/services/second-level

The services is not a folder, I explode $_SERVER['PATH_INFO'] and get the second-level path data.

I have already achieved the first one, but it fails when I enable MultiViews, using a .htaccess file and writing a rewrite.

Options +Indexes +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]

(Which would obviously fail, since it would change the request to services/second-level.php). I know I can write multiple rewrites in the .htaccess, and conditionally redirect.

But the strange fact is that on the live environment (shared hosting), it is working, without any .htaccess file in the root folder. Since it is a shared hosting, I cannot read the configuration file.

Any ideas on what configuration should I change (in apache.conf or *.conf) to achieve the above?

If it matters, I'm using Apache/2.2.22, and this problem started happening after the update.

like image 788
Aaditi Sharma Avatar asked Jan 06 '13 13:01

Aaditi Sharma


People also ask

Should I use multiviews to clean URLs?

Unless you know what you're doing, you should not use MultiViews if you plan to use the Clean URLs feature of Drupal. However, MultiViews is not enabled in a default Apache installation, so it is likely that this note will not apply.

How to disable multiviews in Apache web server?

In /etc/apache2/httpd.conf you should find the section starting <Directory "/Library/WebServer/Documents"> and remove MultiViews from the Options directive there. The same goes for any other paths if your content isn't in that directory.

How do I enable/disable the Clean URLs feature?

Navigate to the Clean URLs configuration page ( Administer > Configuration > Search and metadata > Clean URLs) Wait for the automated Clean URLs test to run. Check or uncheck the Enable clean URLs checkbox. Click "Save configuration".

How to enable clean URLs in WampServer?

On an Apache server, and with the default settings used from Drupal, clean URLs work if: Show activity on this post. Enable the mod_rewrite module then restart the wampserver. I think you can enable the mod_rewrite from the quick launch icon. Right click and view open the apache modules menu and make sure the mod_rewrite is enabled.


1 Answers

I finally figured out how to solve it.

This works, removing the .htaccess file altogether, and changing the Virtual Directory to keep the following settings :

<VirtualHost *:80>
    ServerAdmin my-email-id
    ServerName foo.bar
    DocumentRoot /var/www/sites/foo/

    <Directory /var/www/sites/foo/>
        Options +FollowSymLinks +MultiViews +Indexes
        DirectoryIndex index.php
        AddType application/x-httpd-php .php
    </Directory>

</VirtualHost>

This helps me get all the pages to work, exactly as they were working on the server, without any of the Rewrite Conditions.

like image 130
Aaditi Sharma Avatar answered Oct 20 '22 20:10

Aaditi Sharma