How can I use .htaccess redirection for a partial path?

I had to configure some paths on my site, and I need to use .htaccess to redirect items when the user accidentally accesses the old URL.

For example, my old urls (relative) could be:

/old-path/page1.php
/old-path/page2.php
/old-path/page3.php
etc...

I had to change the path (for this example) to a new path, and I need to configure .htaccess so that anyone who gets to any page with ... / old -path / ... will be redirected to

.../new-path/...

Also, will it fit 301 or will I need to list each page?

+5
source share
1 answer

You can use either mod + alias:

Redirect 301 /old-path /new-path

or using mod_rewrite:

RewriteEngine On
RewriteRule ^/?old-path/(.*)$ /new-path/$1 [L,R=301]

htaccess server/vhost. -, mod_rewrite, mod_alias mod_rewrite .

+8

All Articles