'Redirect Old URLs To new URL (subdirectory to main directory)

I have a website on my subdirectory. My all URL was mywebsite.com/sub/page-or-post-link

I have moved my site to the main directory. mywebsite.com.

I want to redirect my old link to new links.

Like if someone searches mywebsite.com/sub/a-post-or-page.

They should redirect to mywebsite.com/a-post-or-page

How can I do this with javascript, jquery, or with changing .hraccess?



Solution 1:[1]

You can use RewriteRule in .htaccess file. This one should make a job:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^sub/(.*)$ http://mywebsite.com/$1 [R=301,L]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 krzn