Matej
Matej

Reputation: 9805

.htaccess RewriteRule trouble

I am guessing this question has been asked many times, but i could not find one that would perhaps give me what I need.

So.. I can access the scripts by the following url's:

http://website.com/index.php/hello/world
http://website.com/hello/world

Both go to index.php which parses the input (hello/world in this example).

this is my .htaccess:

<IfModule mod_rewrite.c>
Options +FollowSymlinks

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]
</IfModule>

However. When the site is accessed like this:

http://website.com/index.php/hello/world

the RewriteRule outputs something similar to index.php?path=index.php/hello/world

I want to remove that index.php after path= in the RewriteRule

Upvotes: 0

Views: 283

Answers (3)

Matej
Matej

Reputation: 9805

Modifying answer from Stackoverflow answer to suit this question

The .htaccess:

<IfModule mod_rewrite.c>
Options +FollowSymlinks

RewriteEngine On

# Redirect user
RewriteCond %{THE_REQUEST} ^.*index.php.*
RewriteRule ^(.*)index.php(.*)$ $1$2 [NC,R=301,L]

# Handle the query to PHP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]

</IfModule>

Upvotes: 0

Gabriel Santos
Gabriel Santos

Reputation: 4974

Try this

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Upvotes: 0

user562854
user562854

Reputation:

Your .htaccess file should look like this (notice the new rule that checks if index.php is a part of url):

<IfModule mod_rewrite.c>
Options +FollowSymlinks

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php/(.*)$ index.php?path=$1&%{QUERY_STRING} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]

</IfModule>

Upvotes: 1

Related Questions