Redirect 301 Folder content to 1 file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
divedj
Forum Commoner
Posts: 47
Joined: Wed Dec 29, 2010 4:32 am
Location: Malta

Redirect 301 Folder content to 1 file

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Redirect 301 Folder content to 1 file

Post by superdezign »

You can do this with a .htaccess file.

Code: Select all

RewriteRule ^/gallery2/.+$ gallery.html
divedj
Forum Commoner
Posts: 47
Joined: Wed Dec 29, 2010 4:32 am
Location: Malta

Re: Redirect 301 Folder content to 1 file

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Redirect 301 Folder content to 1 file

Post 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.
divedj
Forum Commoner
Posts: 47
Joined: Wed Dec 29, 2010 4:32 am
Location: Malta

Re: Redirect 301 Folder content to 1 file

Post 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 -
divedj
Forum Commoner
Posts: 47
Joined: Wed Dec 29, 2010 4:32 am
Location: Malta

Re: Redirect 301 Folder content to 1 file

Post 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
Post Reply