Rewrite - How to redirect everything without index.php

0

I would like to redirect all requests from my Apache server to the test.php file and remove the index.php file from the root_folder (public_html or DocumentRoot).

I have the following code:

RewriteEngine On
RewriteBase /
RewriteRule . test.php [L]

It works as long as the index.php file is in the root folder. When removing the index.php file Rewrite does not work and Apache displays the list of all files and folders in my root folder.

I would like to know if the request has only to pass through the .htaccess file?

Note: I do not have access to the httpd.conf or apache2.conf file.

    
asked by anonymous 28.09.2015 / 03:08

2 answers

0

Changing the pattern from . to ^ solves the problem. . means that there must be at least one character in the request, since ^ does not. When the / root directory is loaded, which is a blank request, the . pattern will not match that and will look for a index.php defined. If you do not find anything, the default is not loaded because it is not receiving anything.

The code looks like this:

RewriteRule ^ test.php [L]

Font

    
28.09.2015 / 16:10
1

See if this is enough:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.seusite.com.br$
RewriteRule ^$ http://www.seusite.com.br/test.php [L,R=301]

You can be more aggressive and try to use Redirect :

RewriteEngine On
Redirect / http://www.seusite.com.br/test.php

You can still set directoryIndex within .htacess:

DirectoryIndex test.php

I would advise using only the latter case within your .htacess delete index.php and see the result.

    
28.09.2015 / 04:44