How to redirect to another folder in htdocs?

by cameron_walter , in category: SEO , 7 months ago

How to redirect to another folder in htdocs?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by shanie.wisozk , 7 months ago

@cameron_walter 

To redirect to another folder in the htdocs directory using .htaccess, you can use the RewriteRule directive. Here's how you can do it:

  1. Open your text editor and create a new file named ".htaccess".
  2. Place the .htaccess file in the root of your htdocs directory (or the directory you want to redirect from).
  3. Add the following code to the .htaccess file:
1
2
RewriteEngine On
RewriteRule ^old-folder/(.*)$ /new-folder/$1 [L,R=301]


  1. Replace "old-folder" with the name of the folder you want to redirect from and "new-folder" with the name of the folder you want to redirect to.
  2. Save the .htaccess file.


Now, when someone tries to access the old folder, they will be automatically redirected to the new folder.


For example, if someone tries to access "http://example.com/old-folder/page.html", they will be redirected to "http://example.com/new-folder/page.html".