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.
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.
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.
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".
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With