René Sejling
René Sejling

Reputation: 13

htaccess subdirectory URLS to root

I want to redirect all files in a subdirectory to their new root URL.

Old URLS are

www.domain.com/subdirectory/filename-here.html

New location is

www.domain.com/filename.here.html

Old URLs are listed in Google already and need some sort of redirect for these. I'm sure htaccess is the way to go here, but unsure of the solution.

Upvotes: 1

Views: 173

Answers (1)

vmeln
vmeln

Reputation: 1309

RewriteEngine on
RewriteRule %{REQUEST_URI} ^/subdirectory/.*
RewriteRule subdirectory/(.*)$ /$1 [R=301,L]

Tested on here. If it would not work - add shielding to [^/] in this way: [^\/]

Upvotes: 1

Related Questions