Rewrite - How to redirect everything without index.php

Asked

Viewed 1,247 times

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 from my root folder.

I would like to know if there is a way for the request to pass only through the file . htaccess?

Obs.: I don’t have access to the httpd.conf or apache2.conf file.

2 answers

1

See if that’s 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 the Redirect:

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

It is still possible for you to define the directoryIndex inside the . htacess:

DirectoryIndex test.php

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

0


Changing the pattern of . for ^ solves the problem. The . means that there must be at least one character in the request, already the ^ no. When the root directory / is loaded, which is a blank request, the standard . 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 will look like this:

RewriteRule ^ test.php [L]

Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.