.htaccess - CakePHP remove "?url=" from the URL after a redirect -
i'm using cakephp php application.
by default puts .htaccess file:
rewriterule ^(.*)$ index.php?url=$1 [qsa,l]
after rule, doing this:
redirectmatch ^/resources(.*)$ http://domain.com/community$1 [qsa,r=permanent,l]
this makes redirected url:
http://domain.com/community/view/171/?url=resources/view/171/
how can rid of appended "?url=" without breaking cakephp's routing?
if understand question correctly, want have requests /community/*
routed resourcescontroller
. should able acheive adding following app/config/routes.php
.
/** * rename /resources/* /community/* */ router::connect('/community', array('controller' => 'resources')); router::connect('/community/:action/*', array('controller' => 'resources'));
the second rule of magic, mapping matching requests resourcescontroller
, passing in action also.
with above approach can take advantage of reverse-routing:
echo $this->html->link('view community', array( 'controller' => 'resources', 'action' => 'view', $id )); // outputs link `/community/view/171`
the first rule there keep action name out of root url (ie. htmlhelper
links reverse-routed become /community
instead of /community/index
).
following on lazyone's comment, if looking redirect old /resources*
-style links seo purposes, following should trick:
# app/webroot/.htaccess <ifmodule mod_rewrite.c> rewriteengine on rewriterule ^/resources(.*)$ /community$1 [r=301,l] # permanent redirect rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^(.*)$ index.php?url=$1 [qsa,l] </ifmodule>
Comments
Post a Comment