Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
April 16, 2014, 03:28:45 AM

Pages: [1]   Go Down
  Print  
Author Topic: Redirect all pages in a directory to the index page of a new directory  (Read 1818 times)
Polcham
Space Explorer
***
Offline Offline

Posts: 9


« on: January 24, 2013, 09:05:19 AM »

Can anyone tell me how to redirect all the pages in a directory to the index page in a new directory?

For example,  domaincom/directory/26pages.html   all of the 26 pages would be redirected to domaincom/newdirectory/

Can that be done using the redirection tool in the control panel or must one make a direct entry in htaccess?

Thank you.

Polcham
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5806



« Reply #1 on: January 24, 2013, 11:57:39 AM »

Give the control panel method a try -- you can always back it out if it doesn't work right.

Personally, I would do it manually in .htaccess. I'm not sure the control panel redirect tool is flexible enough (it might be). If what you want is any http://domain.com/directory/* to go to http://domain.com/newdirectory/index.html:
Code:
RewriteEngine On
RewriteCond  %{REQUEST_URI}  ^/directory  [NC]
RewriteRule  .  /newdirectory/index.html  [L]
This would be a silent URL rewrite. If you want search engines and so on to update themselves, add R=301, before the L flag. Either way, any URL Query String content should come over automatically.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
Polcham
Space Explorer
***
Offline Offline

Posts: 9


« Reply #2 on: January 25, 2013, 04:46:13 AM »

Thank you.

I added 

RewriteEngine On
RewriteCond  %{REQUEST_URI]  ^/outlook  [NC]
RewriteRule .  /poland-news/index.html  [R=301,L]

The pages in the outlook directory do not redirect to poland-news.  Where did I go wrong?

Thank you.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5806



« Reply #3 on: January 25, 2013, 06:10:36 AM »

Is that a } or ] you have after REQUEST_URI? It should be a }. I would have expected you to get a 500 error if you had a ], so on the assumption it's }...

You are on an Apache server (not Windows IIS), right? This won't work on Windows. The source directory is http://domain.com/outlook/ and you're redirecting it to http://domain.com/poland-news/index.html? If you remove the R=301, does it work then? If that's the case, change the rewrite to http://domain.com/poland-news/index.html.

Also, I assume it's index.html in your target directory -- you could probably leave that off the rewrite if you wanted.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
Polcham
Space Explorer
***
Offline Offline

Posts: 9


« Reply #4 on: January 27, 2013, 12:56:53 AM »

Thanks for the help.  There was an error after the URI.  I fixed the error but it still would not redirect.

I then changed it to this and it did not redirect.

RewriteEngine On
RewriteCond  %{REQUEST_URI} ^/outlook [NC]
RewriteRule  .  /poland-news/index.html  [L]

I use Lunar for hosting.  I have used the redirect function in the control panel to redirect single pages. Those redirection instructions are in the .htaccess file now. I added this new rule at the bottom of the file.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5806



« Reply #5 on: January 27, 2013, 06:58:55 AM »

Is it still not working? I'm not quite clear from your post.

Quote
I use Lunar for hosting.
Let me rephrase my question. Are you on a "Linux" server? That would use Apache web services. If you're on a Windows server (IIS web services), it will ignore your .htaccess file. If you already had an .htaccess file, that the control panel had put commands into, then yes, you can assume you're on Linux.

You might try commenting out (with #) or removing (via control panel) any redirections placed by the control panel, in case they're interfering with the code you just added. Or, you might move the new code up to the top, in case the control panel redirections are doing it wrong.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
Polcham
Space Explorer
***
Offline Offline

Posts: 9


« Reply #6 on: January 27, 2013, 10:53:16 AM »

Hi,

My lunar account information says operating system Linux , apache 2.2.22

I moved the code to the top of the .htaccess file and it now redirects the page  domain/outlook to /poland-news/

But it does not redirect a page such aa outlook/birdflu.html  and http://www.masterpage.com.pl/outlook/amery_izba.html

The code I am using is

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/outlook [NC]
RewriteRule . /poland-news/index.html [R=301,L]

I appreciate your persistence.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5806



« Reply #7 on: January 27, 2013, 11:30:13 AM »

Since moving the new code to the top helped, have you tried the other two things again:
1. change [R=301,L] to [L]
2. change /poland-news/index.html to http://www.masterpage.com.pl/poland-news/index.html

Did either one have any effect? If you use the http: form, put the R=301 back in. This is kind of grasping at straws, because if /outlook redirects, so should /outlook/birdflu.html. Are you sure you're using exactly what is shown here? I see when I type in /outlook, that it's /poland-news/ that comes up, not /poland-news/index.html. Do you have other code in your .htaccess that is concealing the index.html? Is there anything before the 3 lines you added for me? What other statements do you have in your .htaccess?
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
Polcham
Space Explorer
***
Offline Offline

Posts: 9


« Reply #8 on: January 29, 2013, 03:38:52 AM »

Hello,

I have the page redirecting.

The code has to be above the redirect instructions that are added via the control panel redirect function.

Additonally I had to remove all other redirects, related to the oulook directory, that had been added using the control panel redirect function.

Thank you very much for the help.

Logged
Pages: [1]   Go Up
  Print  
 
Jump to: