yii, mamp, htaccess reescribir URL

I am trying to rewrite yii urls but with no luck. I have spent hours going through sites and come up with the same answer each time which doesn't work for me:


I would like to resolve the urls to basic paths e.g

/index.php/site/index to /

/index.php/ads and /index.php/ads/ to /ads

/ads/details?ad=9 to /ads/9

The problem seems to be that the .htaccess has no effect.

Estoy usando:

mamp pro on a mac with lion and the web directory is different to the webserver root. I have set AllowOveride a través de la consola.

The .htaccess is in the same folder as the main index.php but doesn't register even if I create an error.

I have had no problem with other non-yii web directories using an htaccess file

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php





preguntado el 30 de agosto de 12 a las 19:08

as a side note, this .htaccess is not necessary the best. it lets people "see" something when you have a .git folder, or .netbeans or anything... of course, you should not have anything like that. But... I am trying this at the moment : RewriteEngine on RewriteCond %{REQUEST_URI} !\.(jpg|png|css|js|php|ico|txt)$ RewriteRule . /index.php [L] (a .htaccess with 3 lines) -

1 Respuestas

I have a project where my Yii application is in a subfolder as well.

Este es mi archivo .htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

Then in main.php, you'll need to add these lines to the 'rules' array:

'' => 'site/index', // This is for the home page

Is ads the name of your controller? In other words, do you have a file named AdsController.php in your controllers folder? If so, then it will work by default.

Just curious why you're hitting the index.php directly? You should be able to setup your localhost to point directly to your Yii app folder. For example, on my machine I created http:// mytestapp/ and it points to the app's folder in htdocs.

Since you're on a Mac, you need to edit your etc/hosts file as well...

I added a line like this: mytestapp

Espero que ayude...

Respondido 30 ago 12, 21:08

Thanks, it works! It seems the '' => 'site/index' was the issue. I actually do have it set up as http:// mytestapp/ - martyn

was too long editing this. Thanks, it works in a way. The index.php/ads still resolves as well as /ads. Is there a way to stop that? and yii.dev:8888/ads/business funciona pero yii.dev:8888/ads/seller resolves to the server address yii.dev which doesn't work. looking into it now. - martyn

As far as having the URL NOT work with the index.php in it...well, when you visit the Yii Framework site, it works that way as well (yiiframework.com/index.php/about). I guess you could write something that stripped it from the URL and redirected, but I don't see the purpose... Also, did you have a question in your last sentence? At the moment, it doesn't make much sense :) - noticias2001

Was just concerned about duplicate content. As I always prefer one url to one page if possible. The last part was an issue where yii.dev:8888/ads/seller redirects to yii.dev so for some reason the code you gave does not like yii.dev:8888/ads/seller but yii.dev:8888/index.php/ads/seller works. - martyn

As far as duplicate content is concerned, just make sure ALL of your links don't have index.php in the URL path. For the other question, maybe you could add the urlManager array from your main.php in config...I have the same type of setup and none of my pages (including redirected ones) need to include index.php in the path. - noticias2001

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.