I am using Cakephp 2.10. How do I redirect my old URL like https://example.com/folder1/abc to a new URL like https://example.com/pqr.html permanently? I have to do this for more than 200 URLs.
Redirects are generally best done in .htaccess
; it eliminates the need to load and run PHP, so the server load is much lighter.
Thanks for Replying. I know that but I am pretty new to CakePHP and I can see that there are lots of .htaccess files. If I go inside the app folder, I see that there are .htaccess files present inside multiple folders so i am not sure if i have to change inside all the .htaccess files?
I have added like this in all the .htaccess files but it is not working-
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Redirect 301 /folder1/abc /abc.html
</IfModule>
Your RewriteRule ^ index.php [L]
says to redirect everything to index.php
, and stop processing rules, so your Redirect
is never reached. Put it before the first RewriteCond
.
You need this only in the .htaccess
in your webroot.
Thanks for the suggestions.
I have modified the .htaccess files inside the webroot. I have changed the .htaccess file present at app/webroot/.htaccess as below -
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /folder1/abc /abc.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
But still it is not working.
Actually, the below code is working -
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteRule /folder1/abc /abc.html [R=301,L]
</IfModule>
Thanks!