301 help needed

New to mod_rewrite? This is a good place to start.

301 help needed

Postby blueleaf » Tue Jun 23, 2009 1:27 pm

I need help removing a folder from hundreds of URL's. Hopefully something short and sweet of the 301 nature.

Example of what I'm needing to do with hundreds of files:
http://www.example.com/folder/file.html to http://www.example.com/file.html
blueleaf
 
Posts: 5
Joined: Tue Jun 23, 2009 1:18 pm

Postby richardk » Tue Jun 23, 2009 3:36 pm

Try (mod_alias)
Code: Select all
Redirect 301 /folder/ http://www.example.com/
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby blueleaf » Tue Jun 23, 2009 8:44 pm

I just tried that code but I get my 404 page instead of the new page.
blueleaf
 
Posts: 5
Joined: Tue Jun 23, 2009 1:18 pm

Postby richardk » Wed Jun 24, 2009 8:28 am

Hmm. Try the following in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^folder(/(.*))?$ /$2 [R=301,L]


If it doesn't work, check if mod_rewrite is enabled.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby blueleaf » Wed Jun 24, 2009 11:07 am

Thanks. I got the first example working.
blueleaf
 
Posts: 5
Joined: Tue Jun 23, 2009 1:18 pm

Postby blueleaf » Mon Jun 29, 2009 8:54 am

Hi again. I've changed my mind and am using the second example, which also works great.

Now for an additional problem. I have a handful of pages that changed their names a few years ago. I had been using the form of:
Code: Select all
Redirect 301 /folder/oldpage.html http://www.example.com/folder/newpage.html

where "folder" is the same folder addressed in my previous problem. The problem is that these redirects are no longer working. How would I add them to the "folder" solution using mod_rewrite? Also, would they need to come before or after that code?
blueleaf
 
Posts: 5
Joined: Tue Jun 23, 2009 1:18 pm

Postby richardk » Mon Jun 29, 2009 11:31 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^folder/oldpage\.html$ /newpage.html [R=301,L]
RewriteRule ^folder(/(.*))?$ /$2 [R=301,L]

You may need to clear your browser's cache.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby blueleaf » Mon Jun 29, 2009 12:29 pm

Thanks once again! That does the trick so far (I've got to check that nothing else got broken in the process but I doubt that it did).
blueleaf
 
Posts: 5
Joined: Tue Jun 23, 2009 1:18 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 102 guests

cron