1

I used next .htaccess code:

RewriteEngine on
# if the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule ^(.*)$ index.php/$1 [L]

It work nice, but it's available all pages with index.php and without it, for example:

http://localhost/framework/about
http://localhost/framework/index.php/about // need redirect to http://localhost/framework/about

I want to redirect all request with index.php to without index.php with SEO reasons, How can I remove index.php?

3
  • 1
    Where is your htaccess ? In your framework folder ? Commented Mar 1, 2014 at 10:12
  • You can use ForceType for this as well. It will allow you to drop the .php and does not require the RewriteEngine Commented Mar 1, 2014 at 10:20
  • @Tigger Can you show me example of code? Commented Mar 1, 2014 at 10:22

2 Answers 2

2

Try this

RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^/]+)/index\.php/(.+)\s [NC]
RewriteRule ^.*$ /%1/%2 [R=301,L]

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


  1. %{THE_REQUEST} contains the full HTTP request line sent by the browser to the server (e.g., GET /index.html HTTP/1.1)
  2. The condition RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^/]+)/index\.php/(.+)\s [NC] matches something like GET /xxx/index.php/yyyy where xxx would be framework and yyy would be about/something/what/you/want or just about if you want (could be also POST or another instead of GET but it does not really matter here).

Example: /framework/index.php/everything/about/me will be redirected to /framework/everything/about/me or /framework/index.php/about will be redirected to /framework/about

Sign up to request clarification or add additional context in comments.

4 Comments

Can you explain me RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^/]+)/index\.php/(.+)\s [NC], please? What is %{THE_REQUEST}? %{REQUEST_URI} is a same that %{THE_REQUEST}?
Sure. I edited my answer with an explanation for %{THE_REQUEST} and for the condition
I can't understand why you use %1 and %2 instead $1 and $2? There are two different things?
Yes it's different: % when captured in RewriteCond and $ when captured in RewriteRule
1

Pretty sure the following will redirect everything to the $_SERVER['PATH_INFO'] var in index.php

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !.index.ph.*
RewriteRule ^(.*)$  /index.php

It has been a while since I've used this method.

Alternatively you can use ForceType like this:

<Files *>
    ForceType application/x-httpd-php
</Files>
<Files *\.*>
    ForceType None
</Files>

This will allow you to have a PHP file called about (no extension) and have it executed as PHP.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.