Suppose I have example.com and removed 5 directories.They consist a lot of URL.Because I give penalty from google search engine, I decide to create a page and redirect (permanent 301) those to my page.
As you know, I have to use .htaccess , But I use the following rule:

RedirectMatch 301 /old-directory/(.*) /new-directory/$1

Unlike of above rule, I need to redirect to new page, not new dir.
How to implement it?


...I get penalty from google search engine

The "penalty" is probably just that you have removed a lot of your content! Naturally, if these pages were previously indexed and receiving search engine traffic then you are going to lose visitors.

However, redirecting all these lost pages to a single "irrelevant" page is probably not going to help either. That's probably not going to be a good user experience and Google will soon realise the page being redirected to is unrelated, so will probably just drop it anyway.

If you don't have a new version of these pages to redirect to then you are perhaps better off customising your "custom 404" some more with more relevant information for the user in the hope that they will stick around.

Coming back to the technical aspect of redirecting 5 directories to a single page:

RedirectMatch 301 ^/(olddir1|olddir2|olddir3|olddir4|olddir5)/ /path/to/new/page

You basically just need to remove the $1 from the URL substitution in your original code.

Note that if you already have some RewriteRule directives then you should probably be using mod_rewrite instead of mod_alias in order to prevent conflicts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.