Reputation: 449
I see in my logs that some users are trying to access my site using this url format:
http://mysite.com//home/article/123
(note the double slash after the domain). I want these to execute the actions of the corresponding "single slash" urls. So I tried adding a route like this:
Router::connect('//home/article/:id/*', array(
'controller'=>'article',
'action'=>'view'),
array('pass' => array('id'),
'id' => '[0-9]+',
));
But I get this error:
Error: [MissingPluginException] Plugin could not be found.
I tried also with these Rewrite rules:
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
But the url did not change and I got the same error.
Why this is wrong? What rule I need to add to cakephp routing (or to Apache RewriteRule)?
Upvotes: 0
Views: 1342
Reputation: 107
It's a problem with cache.
In my case i have double slash in my URL on Nginx server. The solution is removing this cache. To do this :
rm -rf /path/to/application/app/tmp
Now you need to recreate file located in tmp file :
mkdir /path/to/application/app/tmp/cache
mkdir /path/to/application/app/tmp/logs
mkdir /path/to/application/app/tmp/purifier
Don't forget to check the permissions of each file to avoid error such as Warning(512).
Upvotes: 1
Reputation: 14544
You need to do this with rewrite rules in your .htaccess. However, the rewrite you are using won't fix the problem, as it will only remove double slashes after the domain name and first slash.
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
This rule will only work on the following part of the URL:
home/articles/123
So it will fix this:
http://www.example.com/home//articles/123
But not this:
http://www.example.com//home/articles/123
What you need to do is add this rule instead, or as well as the other one, if you need to fix both cases:
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301,L]
Upvotes: 0
Reputation: 7575
The router does not redirect, it just maps urls to controller actions. If you want to remove //
do it on the webserver rewrites.
Upvotes: 0