renaud
(Rtheuillon)
March 12, 2014, 12:47pm
1
Hi there,
This should be easy with .htaccess but for some reason I am struggling.
I want for example that:
http:://mywebsite/site/contact.html
always redirect to
http:://mywebsite/site/contact
My URL manager config is
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
),
I am playing with my .htaccess the closest I got to something is
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ $1 [R=301,L]
But I get a funny result (at least it did remove the html…):
http://localhost:80/C:/xampp/htdocs/mywebsite/site/contact
Anyway I think there is something Yii specific that is causing a problem.
Any idea?
Thanks
Renaud
Hi,
You may use like,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Thanks
renaud
(Rtheuillon)
March 12, 2014, 2:17pm
3
Thank you for your suggestion Ghanshyam, I tried that but I get:
The system is unable to find the requested action "contact.html".
renaud
(Rtheuillon)
March 15, 2014, 11:54am
4
Anybody? I still cannot find a solution, this seems to be a trivial thing though…
alirz23
(Ali Raza)
March 15, 2014, 1:01pm
5
Yii will not serve your static files its complaining about action not found if you trying to fake .html in your actions use the suffix property of urlmanager
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'urlSuffix'=>'.html'
),
renaud
(Rtheuillon)
March 15, 2014, 5:24pm
6
alirz23:
Yii will not serve your static files its complaining about action not found if you trying to fake .html in your actions use the suffix property of urlmanager
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'urlSuffix'=>'.html'
),
Thanks alirz23, but this is not what I am trying to do. This above will add .html to all my URLs inside the website.
I want that all my actions/link to have no .html in the URL. But if the user by mistake adds .html it is still understood, and the URL is stripped from the .html.
renaud
(Rtheuillon)
March 21, 2014, 10:45am
7
Any url rewrite specialist?