-3

How to remove "index.php" and also wants to remove "?r=". I want to make URLs user friendly.

How to remove "index.php" and also wants to remove "?r=". I want to make URLs user friendly.

1

2 Answers 2

2

Do these 3 steps:

  1. Enable Url re-writing on Apache.

  2. Place .htaccess on root of your project

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule . index.php
    

In your configuration protected/config/main.php set showScriptName to false like this to your url manager components >> urlManager

'urlManager'=>array(
  'urlFormat'=>'path',
  'rules'=>array(
      '<controller:\w+>/<id:\d+>'=>'<controller>/view',
      '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
      '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
  ),
  'showScriptName'=>false,
)
Sign up to request clarification or add additional context in comments.

1 Comment

If you're having trouble like I just did - make sure "AllowOverride All" is set in the appache /etc/httpd/conf/httpd.conf file - otherwise your .htaccess file is not going to work!
1

1) enable your urlManager in protected>>config>>main.php by adding these line to the array:

    'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
  'showScriptName'=>false,
    ),

2) The .htaccess file should be in the site root in the same of index.php level and should be like that:

    RewriteEngine on

    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php)

    # otherwise forward it to index.php
    RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]

3) make sure that your Apache configuration AllowOverride All not None

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.