johnohod
johnohod

Reputation: 494

.htaccess redirect multiple URLs to one .html

I'm trying to have a URL structure like this:
www.mydomain.com/aaa/bbb/ccc
www.mydomain.com/aaa/ddd/eee
www.mydomain.com/aaa/fff/ggg

All of the above url's should redirect to: www.mydomain.com/aaa.html

Today I use this in .htaccess:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} (.*)/$
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule (.*)/$ $1.html [L]

If I try to input: www.mydomain.com/aaa/bbb/ccc in a browser, the server will lookup: www.mydomain.com/aaa.html/bbb/ccc and not www.mydomain.com/aaa.html

Upvotes: 2

Views: 832

Answers (1)

dvergur
dvergur

Reputation: 36

I have similar scenario where I like to redirect all requests from permanently moved directories to new location (in my case new domain)

RewriteRule ^aaa\/?(.*)$ "http\:\/\/mydomain\.com\/aaa.html" [R=301,L]

Take note of the 301, "Moved Permanently" code. That seam to require using the full url in the redirect path.

Hope this can help you.

Upvotes: 1

Related Questions