# How do I redirect an old URL like https://example.com/folder1/abc to a new URL like https://example.com/abc.html permanently in a Cakephp?

**URL:** <https://discourse.cakephp.org/t/how-do-i-redirect-an-old-url-like-https-example-com-folder1-abc-to-a-new-url-like-https-example-com-abc-html-permanently-in-a-cakephp/7259>\
**Category:** Need Help\
**Created:** [February 11, 2020, 4:04am UTC](https://discourse.cakephp.org/t/how-do-i-redirect-an-old-url-like-https-example-com-folder1-abc-to-a-new-url-like-https-example-com-abc-html-permanently-in-a-cakephp/7259 "2020-02-11T04:04:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandy86](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sandy86](https://discourse.cakephp.org/u/sandy86)\
**Post date:** [February 11, 2020, 4:04am UTC](https://discourse.cakephp.org/t/how-do-i-redirect-an-old-url-like-https-example-com-folder1-abc-to-a-new-url-like-https-example-com-abc-html-permanently-in-a-cakephp/7259/1 "2020-02-11T04:04:59Z")

</div>

I am using Cakephp 2.10. How do I redirect my old URL like [https://example.com/folder1/abc](https://example.com/folder1/abc) to a new URL like [https://example.com/pqr.html](https://example.com/pqr.html) permanently? I have to do this for more than 200 URLs.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 11, 2020, 4:41am UTC](https://discourse.cakephp.org/t/how-do-i-redirect-an-old-url-like-https-example-com-folder1-abc-to-a-new-url-like-https-example-com-abc-html-permanently-in-a-cakephp/7259/2 "2020-02-11T04:41:04Z")

</div>

Redirects are generally best done in `.htaccess`; it eliminates the need to load and run PHP, so the server load is much lighter.

---

<div class="post-metadata">

**Author:** ![sandy86](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sandy86](https://discourse.cakephp.org/u/sandy86)\
**Post date:** [February 11, 2020, 5:09am UTC](https://discourse.cakephp.org/t/how-do-i-redirect-an-old-url-like-https-example-com-folder1-abc-to-a-new-url-like-https-example-com-abc-html-permanently-in-a-cakephp/7259/3 "2020-02-11T05:09:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sandy86](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sandy86](https://discourse.cakephp.org/u/sandy86)\
**Post date:** [February 11, 2020, 6:11am UTC](https://discourse.cakephp.org/t/how-do-i-redirect-an-old-url-like-https-example-com-folder1-abc-to-a-new-url-like-https-example-com-abc-html-permanently-in-a-cakephp/7259/4 "2020-02-11T06:11:56Z")

</div>

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>
```

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 11, 2020, 3:08pm UTC](https://discourse.cakephp.org/t/how-do-i-redirect-an-old-url-like-https-example-com-folder1-abc-to-a-new-url-like-https-example-com-abc-html-permanently-in-a-cakephp/7259/5 "2020-02-11T15:08:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sandy86](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sandy86](https://discourse.cakephp.org/u/sandy86)\
**Post date:** [February 12, 2020, 4:28am UTC](https://discourse.cakephp.org/t/how-do-i-redirect-an-old-url-like-https-example-com-folder1-abc-to-a-new-url-like-https-example-com-abc-html-permanently-in-a-cakephp/7259/6 "2020-02-12T04:28:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sandy86](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sandy86](https://discourse.cakephp.org/u/sandy86)\
**Post date:** [February 12, 2020, 6:09am UTC](https://discourse.cakephp.org/t/how-do-i-redirect-an-old-url-like-https-example-com-folder1-abc-to-a-new-url-like-https-example-com-abc-html-permanently-in-a-cakephp/7259/7 "2020-02-12T06:09:19Z")

</div>

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!
