- I want to remove index.php from the middle of the URL.
- I am using Dreamhost Webhosting.
- And Believe me, Dreamhost Webhosting configuration is very different from others.
- Normal Webhosting configuration is not working in Dreamhost.
Here is the problem I am facing:
PROBLEM 1:
The link below:
https://www.example.com/index.php/gallery
Should redirect to:
https://www.example.com/gallery
PROBLEM 2:
The link below:
https://www.example.com/index.php/profile/juhi/168
Should redirect to:
https://www.example.com/profile/juhi/168
PROBLEM 3:
The link below:
https://www.example.com/index.php
Should redirect to:
https://www.example.com/
htaccess code is below:
RewriteEngine On
# Existing files and directories remain accessible
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
# Redirect the rest
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]
The part of the URL-path after
/index.php(a valid file), ie./galleryin this example, is called "additional pathname information" (aka path-info for short). (This is used by many CMS to route the URL when mod_rewrite/.htaccessis not available.)To remove the
/index.phppart of the URL you could add the following redirect directive immediately after theRewriteEnginedirective.Test first with a 302 (temporary) redirect and only change to 301 (permanent) - if that is the intention - once you have confirmed that it works as intended. 301s are cached persistently by the browser so can make testing problematic.
Aside:
As I mentioned in comments, your
.htaccessdirectives are rewriting the request to a query string (not path-info as mentioned above). This means that your pages are accessible via a 3rd URL. For example:FWIW, nothing mentioned in your question, or the solution, is specific to any particular web-host.