Page 1 of 1

Redirect 301 Folder content to 1 file

Posted: Mon Apr 25, 2011 7:31 am
by divedj
I need to redirect various files left from an old photogallery script to one new file

I have plenty of urls indexed by search engines looking like

Code: Select all

http://www.domain.com/gallery2/key/Malta?g2_highlightId=147
or
http://www.domain.com/gallery2/updates?g2_albumId=1319&g2_itemId=3433&g2_fromNavId=xe18d6500

I still have an empty folder gallery2 and what I have tried is the following:

Code: Select all

Redirect 301 /gallery2/ http://www.domain.com/gallery.html
But this leaves me whith an url like

Code: Select all

http://www.domain.com/gallery.htmlkey/Malta?g2_highlightId=147
which does mess up all the following links.

Is there any possibilety to catch all requests going in to the folder /gallery2/ and redirect or rewrite them to just

Code: Select all

http://www.domain.com/gallery.html

Thanks for any advise

Re: Redirect 301 Folder content to 1 file

Posted: Mon Apr 25, 2011 8:51 am
by superdezign
You can do this with a .htaccess file.

Code: Select all

RewriteRule ^/gallery2/.+$ gallery.html

Re: Redirect 301 Folder content to 1 file

Posted: Tue Apr 26, 2011 12:29 am
by divedj
Thanks for your reply.

I tryed but any incoming request still ends up with a 404 - page not found.

Maybe it's something to do with the rest of my htaccess file which is in the root directory.

Code: Select all

RewriteEngine on
RewriteRule ^/gallery2/.+$ gallery.html

RewriteCond %{REQUEST_URI} /(.*).html
RewriteRule (.*) /index.php?include=%1

Redirect 301 /Exhibit/exhibition_main.html http://www.domain.com/exhibition-main.html
Thanks for any suggestions

Re: Redirect 301 Folder content to 1 file

Posted: Tue Apr 26, 2011 5:59 am
by superdezign
Was it work before you added that line? If so, replace the "+" with "*". I believe older versions of Apache don't use PCRE and I'm not exactly sure where the differences lie.

Re: Redirect 301 Folder content to 1 file

Posted: Tue Apr 26, 2011 6:52 am
by divedj
Thanks again,

it is everything working exept incoming requests using http://www.domain.com/gallery2/whatsoeverComesAfter ends up with an 404 error.

It just doesn't rewrite into http://www.domain.com/gallery.html

Replacing + with * doesn't make a difference.

However, thinking a little further, when does the actual rewriting take place?

All the main content is dynamicly called and get included with php include($_GET('content')) and that is run through a filter, taking everything out exept a-z, 0-9, . and -

Re: Redirect 301 Folder content to 1 file

Posted: Wed Apr 27, 2011 7:45 am
by divedj
I have it working.

Code: Select all

    RedirectMatch 301 ^/gallery2/ http://www.domain.com/gallery.html
did the trick.

However, there is still one problem remaining.

http://www.domain.com/gallery2/whatsoev ... ComesAfter

gets rewritting to

http://www.domain.com/gallery.html?include=ComesAfter

it doesn't realy change anything but it would be nice if there is a way to make the new url just look like

http://www.domain.com/gallery.html

I am still happy for any suggestions.

Thanks a lot