John Brad
John Brad

Reputation: 467

how to add index.php in the URL through htaccess

Actually I need to add index.php in my application URL through htaccess file.

My URL is like this.

http://localhost:8080/myapp/xyz/abs.html

I need to change this into.

http://localhost:8080/myapp/index.php/xyz/abs.html

Can anyone tell me what i need to be write in htaccess file.

Any Help will be appreciating.

Thanks.

Upvotes: 5

Views: 5010

Answers (3)

Amit Verma
Amit Verma

Reputation: 41219

Try this in your htaccess

RewriteEngine on 
RewriteCond %{THE_REQUEST} /myapp/xyz/([^.]+)\.html [NC]
RewriteRule ^ /myapp/index.php/xyz/%1.html [R,L,NC]

Upvotes: 0

anubhava
anubhava

Reputation: 785098

Have this rule in /myapp/.htaccess:

RewriteEngine On
RewriteBase /myapp/

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php/$1 [L]

Upvotes: 5

DocRoot
DocRoot

Reputation: 1201

Presumably an internal rewrite is required, not an external redirect? In which case, try something like the following, using mod_rewrite in your root .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_URI} !/index\.php/
RewriteRule ^myapp/(.*) /myapp/index.php/$1 [L]

The RewriteCond directive is required to prevent a rewrite loop. (Only rewrite if it doesn't already contain "/index.php/".)

Upvotes: 1

Related Questions