You are viewing revision #9 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
Maybe it looks simple, but some time ago I need some time to find a solution of this case. I finally got it, and I want to share that I also experienced such cases. So that it can make reference.
Neither let us do the steps:
- Make sure that the hosting / your pc mod_rewrite module is active. if not actively try to activate in a way, open the httpd.conf file. You can check this in the phpinfo.php to find out.
change this setting : ~~~
LoadModule rewrite_module modules/mod_rewrite.so ¶
to be
LoadModule rewrite_module modules/mod_rewrite.so ~~~
- then go to .htaccess file, and try to modify to be:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
if above does not work try with this: ~~~ RewriteEngine on
if a directory or a file exists, use it directly ¶
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
otherwise forward it to index.php ¶
RewriteRule . index.php
* move .htaccess file to root directory, where is index.php thare.
www
- protected
- index.php
- .htaccess
* Set main.php in your yii configuration, at component :
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
),
- so.., good luck
For reference material I managed to do in my personal website (check my profile).
NB: This for hide index.php
more on mod_rewrite
Excellent article on how mod_rewrite works - http://www.workingwith.me.uk/articles/scripting/mod_rewrite#writeComment
From the site - "mod_rewrite is used for rewriting a URL at the server level, giving the user output for that final page. So, for example, a user may ask for http://www.somesite.com/widgets/blue/, but will really be given http://www.somesite.com/widgets.php?colour=blue by the server."
Unclear purpose, example and .htaccess
Hi,
your article is a bit unclear about what is the goal you are trying to reach? Perhaps 1-2 examples would make things clearer:-) Also what is the final content of .htaccess file? (you may want to put it into solid code block pretty formatted).
Cheers
Lubos
hide index.php
this article to hide index.php url:
for example:
~~~
http://mydomain.com/index.php/contact
~~~
to be
~~~
http://mydomain.com/contact
~~~
showScriptName will not suffice?
Thanx for pretty formatting, now it's clearer what you want to achieve.
Yet, the question is:
What is the benefit over setting the built-in paramater for urlManager in configuration:
'showScriptName'=>false,
http://www.yiiframework.com/doc/api/1.1/CUrlManager#showScriptName-detail
Cheer, Lubos
urlManager
thank you, you are right.
This can not be run if not in the main config settings.
~~~
Set main.php in your yii configuration, at component :
[php]
'urlManager'=>array(
'urlFormat'=>'path', 'showScriptName'=>false,
'caseSensitive'=>false,
),
~~~
Not only check mod_rewrite instalation
To get mod_rewrite working not only modrewrite must be installed, but also check in the Apache directory config (/etc/apache2/sites-enabled/000-default_ on Ubuntu installed via apt-get) if the rule "AllowOverride None" exists in your project's directory config. If so, change it to "AllowOverride All". I have spent hours because of this thing, so it's my tip to get things working.
Perfect
Thank you! It works! :D
RewriteBase PROJECTNAME
I am using WAMP, it works after i include the line:
RewriteBase PROJECTNAME
in file [.htaccess]
thanks for article.
win32 apache config
As thiromi said, make sure that you change the "AllowOverride" flag to "All"
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # **AllowOverride All**
Hello, May you take a look on my yii topic
Hello, May you take a look on my yii topic
yiiframework.com/forum/index.php/topic/33491-user-friendly-urls/pagep161195fromsearch1#entry161195
I have made what is required but it does not work.
I dont understand why.
Thank you!
That Sounds good
Thanks for this great article
I just tried it but I fail first because I forget and put this variables
'urlFormat'=>'path', 'showScriptName'=>false, 'caseSensitive'=>false,
inside the array of the rules
:)
I just a newbie with YII :) so I'm just confused
Thank you again
One more thing...
Also, if you're on a virtual directory (e.g. using
Alias /dir/ "/dir/"
on your apache configuration) you MUST use a
statement on your .htaccess file, other than the rewrite won't work again.
.htaccess
by "moving .htaccess to webroot" you mean delete .htaccess within protected folder? if so it's horrible for security cause the protected folder is accessible for anyone.
i think you mean copy that .htaccess and use it for this urlManager and keep the other one.
Nice Article
Very Nice article ..thank you so much this works for me..
how to change the URL path?
how to change Url path like -
Instead of -
17695 Got it
i found the solution, simply add below script into urlManager array in main config file.
eg. -
'routeVar'=>'route'
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.