Yii Framework Forum: URL and .htaccess - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

URL and .htaccess Handle URLs with .htaccess Rate Topic: ***** 1 Votes

#1 User is offline   Muhammad Nauman Yousaf 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 06-February 12

  Posted 25 July 2012 - 05:53 AM

I want clear url for SEO point of view. i have changed and added the following .htaccess code and configuration in main.php
//.htaccess:
======================

IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

=================================

//main.php
====================================
'urlManager' => array(

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

this issue is i have a number of links in my application with ?r=controller/method how can i handle it with .htaccess without changing all the URLs format in my application.

Thanks in advance
1

#2 User is offline   pavlepredic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 30-August 11

Posted 26 July 2012 - 03:26 AM

Once you changed CUrlManager::$urlFormat to 'path', all your URLs should automatically take the path form (example.com/controller/action) - provided that you used Yii::app()->createUrl() method to build your URLs. If you hardcoded URLs, then you should replace them all with a call to createUrl() method. This may be a bit more work, but it is the proper way of doing things.

So if you have something like this in your view:
<a href='index.php?r=site/login'>Login</a>

You should replace it with:
echo CHtml::link('Login', array('site/index'));

Or, if you don't want to create an <a> tag, just call:
Yii::app()->createUrl('site/index');

0

#3 User is offline   Muhammad Nauman Yousaf 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 06-February 12

Posted 26 July 2012 - 05:37 AM

View Postpavlepredic, on 26 July 2012 - 03:26 AM, said:

Once you changed CUrlManager::$urlFormat to 'path', all your URLs should automatically take the path form (example.com/controller/action) - provided that you used Yii::app()->createUrl() method to build your URLs. If you hardcoded URLs, then you should replace them all with a call to createUrl() method. This may be a bit more work, but it is the proper way of doing things.

So if you have something like this in your view:
<a href='index.php?r=site/login'>Login</a>

You should replace it with:
echo CHtml::link('Login', array('site/index'));

Or, if you don't want to create an <a> tag, just call:
Yii::app()->createUrl('site/index');


Thank You very much
0

#4 User is offline   Muhammad Nauman Yousaf 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 06-February 12

Posted 26 July 2012 - 05:39 AM

Can you help me in the following regard:
i have a module like this:
http://localhost/ver...tion/group_id/2
i the group_id=2
when i called this url Error 404 occurs
0

#5 User is offline   dty 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 30-December 10
  • Location:Mount Laurel, New Jersey

Posted 07 April 2013 - 09:09 AM

View Postitsallaboutnomy, on 25 July 2012 - 05:53 AM, said:



IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php




for the life of me, i cannot strip index.php from the URL. No idea why. I have it now that domain.com/index.php/site/login works, but obviously that's the ugliest thing in the world. my .htaccess looks the same as yours. in the same dir was my index.php where i create my yii app.

Any tips? :/
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users