Matthijn
Matthijn

Reputation: 3234

.htaccess all request to other file

Currently I have the following .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ public/index.php/$1 [L]
</IfModule>

Which works allmost perfect.

It rewerites urls like http://domain.com/something/ to the public/index.php file, like a charm, except when it is a file, just like it should.

However http://domain.com (without any path appended) (there is no index.php in the root, so it gives a 404 at the moment) is not being rewrited, how can I change this .htaccess so it rewrites this url too?

The index file is in public/index.php I want it to load that file through the use of .htaccess

Thanks

Upvotes: 0

Views: 1058

Answers (3)

mbfisher
mbfisher

Reputation: 306

You could try:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ public/index.php

RewriteBase should prepend the rule pattern with a leading slash, forcing it to match the root path.

Untested!

Upvotes: 1

David
David

Reputation: 2065

I believe to rewrite the root, you can simply do something along the lines of:

RewriteRule ^$ location/of/root/file [L]

Upvotes: 1

transilvlad
transilvlad

Reputation: 14532

What you have there is inspired by WordPress?? It's a bad idea as it tell Apache to always check if the path is a file or a directory before redirecting.

I have something like this

RewriteEngine On
RewriteCond %{REQUEST_URI} !^.*/(css|images|javascript)(.*) [NC]
RewriteCond %{REQUEST_URI} !\.(swf|ico|php|xml)$ [NC]
RewriteCond %{REQUEST_URI} !robots.txt
RewriteRule (.*) index.php?page=$1&%{QUERY_STRING} [PT]

The first condition restricts this redirect from working in specific folders. The seconds does it for specific extensions. You can guess what the third does :)

Upvotes: 0

Related Questions