Dave2345
Dave2345

Reputation: 493

why isn't my mod_rewrite working even when it is enabled?

In my phpinfo() command it shows mod_rewrite is enabled, yet i'm still getting apache's default not found page instead of my own "404" page. Here is my .htaccess:

RewriteEngine on
RewriteRule ^(.*)$ test_modrw.php

Here is the section in phpinfo that shows mod_rewrite is enabled:

enter image description here

EDIT

Thanks Agama. But still one issue, I can still directly access files in the root. For example:

example.com/test_file.php

Can still be accessed instead of the .htaccess routing everything to index.php which is also in the root. Here is my .htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

EDIT

Can you guys upvote this question as well as others of mine? S.O. has banned me because they think my questions are of low-quality because of little upvotes.

Upvotes: 2

Views: 875

Answers (2)

Agam Banga
Agam Banga

Reputation: 2693

Please change the conf as below to allow the access in your /etc/apache2/sites-available or /etc/httpd/conf.d/

Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all

Upvotes: 2

Capsule
Capsule

Reputation: 6159

A better answer would be to check that AllowOverride is set to all and not none in the necessary <Directory> directive (find the one that corresponds to files you serve). Just be conscious it will enable your .htaccess files to override a lot of options from the config.

Only do that if you know what you are doing (aka, don't do that on a server where other users can upload files as they might be able to change some options that you don't want changed). If you're the only one hosting sites on this server, all good.

If you're conscious about security and/or what other users can do, for the purpose of rewriting things, you could just change AllowOverride none to AllowOverride FileInfo Options

FileInfo will enable the rewrite rules and Options will enable what follows.

Then, in your .htaccess file, just add at the beginning:

Options +FollowSymLinks -MultiViews

By doing that, you'll ensure the FollowSymLinks option is enabled, and MultiViews is disabled (as pointed out in a comment, it will cause issues with rewrites rules in certain scenario - typically, when you have double extensions like .en.php, .fr.php and Multiviews kicks in), no matter what the default Apache config is.

This is far better to control that on a folder/vhost basis than on the server level.

I would also highly recommend to disable Indexes altogether from the main config file as it's an open door to list unwanted files (basically, it shows the content of any folder that doesn't have an index file).

Upvotes: 1

Related Questions