WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-29-2006, 06:36 PM
WebProWorld New Member
 

Join Date: Oct 2005
Posts: 20
djstreet RepRank 0
Default Challenge: Mod Rewrite : Changin all link _ to -

I've tried for a month, numerous items, different strings, PHP, etc. nothing, NOTHING! I need help please PLEASE... The bots keep wanting to look at my forums old _ in the link and not the new -.




Context:

I switch my forum from underscores to hyphens. Trouble is, I can't get the htaccess to 301 redirect so it now looks like I have duplicate content.

Here's what I've done:

Redirect 301 /forum/Buy_Sell_Trade_Forums_C15/ http://www.discusswireless.com/forum...de-Forums-C15/

multiplied by all the different categories I have. This worked, however, it only worked for that directory and did not apply to forum categories and posts underneath it.

Another problem is the length of the posts will vary posts by post and forum by forum; I need a more efficient method of changing ALL _ to -

I've tried this piece:

RewriteRule ^forum/([^_]*)_([^_]*)_([^_]*)/([^_]*)_([^_]*)_([^_]*)/([^_]*)_([^_]*)_([^_]*)_([^_]*)/$ /forum/$1-$2-$3/$4-$5-$6/$7-$8-$9-$10/ [L,R=301]

But that's not working.....I'm looking for something to change everything in one swoop.

I could poetntially have links this long:

http://www.mysite.com/forum/Discuss-...-Strobe-P2523/

(of course with underscores)


Any htaccess gurus out there? I also tried this: RewriteRule ^/([-a-zA-Z0-9/]+)_(.+)$ /$1-$2 [L]

But that didin't work.....

ANd I've tried calling a script.php from htaccess in attempts to get it to work:

Code:

RewriteRule ^/forum/.+_.+ script.php



script.php:
Code:

$newUrl = str_replace('_', '-', $_SERVER["REQUEST_URI"]);
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $newUrl);




Any thoughts at all? Someone must know, even a 'that's impossible :P" thanks.
Thanks in advance
__________________
Qualified SEO Consultation
Reply With Quote
  #2 (permalink)  
Old 07-30-2006, 10:43 AM
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Cornwall, UK
Posts: 829
speed RepRank 1
Default

All that springs to mind is to create a file called moved.php with the following in it:
Code:
<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.discusswireless.com/forum/' . str_replace('_', '-', $_GET['u']));
?>
Then put the following in .htaccess
Code:
RewriteEngine on
RewriteRule ^forum/(.*_.*)$ moved.php?u=$1
It seems to work for some limited testing.
__________________
TOLRA Micro Systems Limited US & UK Web Hosting with Continuous Data Protection
Web Directory : Web Directory Script
Reply With Quote
  #3 (permalink)  
Old 07-30-2006, 03:35 PM
WebProWorld New Member
 

Join Date: Oct 2005
Posts: 20
djstreet RepRank 0
Default

Quote:
Originally Posted by speed
All that springs to mind is to create a file called moved.php with the following in it:
Code:
<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.discusswireless.com/forum/' . str_replace('_', '-', $_GET['u']));
?>
Then put the following in .htaccess
Code:
RewriteEngine on
RewriteRule ^forum/(.*_.*)$ moved.php?u=$1
It seems to work for some limited testing.

Thanks for the input. What limited testing did you run? I can't get it to work even for basic html files in a sub folder.....
__________________
Qualified SEO Consultation
Reply With Quote
  #4 (permalink)  
Old 07-30-2006, 03:50 PM
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Cornwall, UK
Posts: 829
speed RepRank 1
Default

stuff.tolranet.co.uk/wpw/htaccess/file_name.html when you access that it will rewrite to file-name.html

Where did you put the .htaccess file in the forum folder or in the folder above it?

If you put it in the foum folder than change it to be:
Code:
RewriteEngine on
RewriteRule ^(.*_.*)$ moved.php?u=$1
__________________
TOLRA Micro Systems Limited US & UK Web Hosting with Continuous Data Protection
Web Directory : Web Directory Script
Reply With Quote
  #5 (permalink)  
Old 07-30-2006, 07:37 PM
WebProWorld New Member
 

Join Date: Oct 2005
Posts: 20
djstreet RepRank 0
Default

Quote:
Originally Posted by speed
stuff.tolranet.co.uk/wpw/htaccess/file_name.html when you access that it will rewrite to file-name.html

Where did you put the .htaccess file in the forum folder or in the folder above it?

If you put it in the foum folder than change it to be:
Code:
RewriteEngine on
RewriteRule ^(.*_.*)$ moved.php?u=$1
I did use the above code when I moved it to a subfolder. Actually no, I used RewriteRule ^newsletter/

because that was the oflder for the test.

My forum folder is somewhere in th cgi-bin, however, it loads on the homepage and the htaccess in the root has a bunch of entries to call the forum from wherever so it loads as the index.

www.discusswireless.com

I don't know if that affects the placement of htis particular mod_Rewrite code..... thoughts?

thanks for the help.
__________________
Qualified SEO Consultation
Reply With Quote
  #6 (permalink)  
Old 07-31-2006, 04:07 AM
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Cornwall, UK
Posts: 829
speed RepRank 1
Default

Quote:
I did use the above code when I moved it to a subfolder. Actually no, I used RewriteRule ^newsletter/
Try using the RewriteRule as I gave it to you: ^(.*_.*)$ moved.php?u=$1, with both the .htaccess and moved.php being placed in the newsletter folder. You should not have any folder names in the rewrite rule for this case.

Note: You will need to update moved.php with the correct target path.
__________________
TOLRA Micro Systems Limited US & UK Web Hosting with Continuous Data Protection
Web Directory : Web Directory Script
Reply With Quote
  #7 (permalink)  
Old 08-08-2006, 04:35 PM
WebProWorld New Member
 

Join Date: Oct 2005
Posts: 20
djstreet RepRank 0
Default

Quote:
Originally Posted by speed
Quote:
I did use the above code when I moved it to a subfolder. Actually no, I used RewriteRule ^newsletter/
Try using the RewriteRule as I gave it to you: ^(.*_.*)$ moved.php?u=$1, with both the .htaccess and moved.php being placed in the newsletter folder. You should not have any folder names in the rewrite rule for this case.

Note: You will need to update moved.php with the correct target path.



This should work:
Code:
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^forum/.*_.*$ script.php [L]


script.php:
Code:
<?php

header('Location: http://' . getenv('HTTP_HOST')
. str_replace('_', '-', getenv('REQUEST_URI')), true, 301);



The above is what i recently used and was ssuccessful, are there glaring errors within this particular option? Tx
__________________
Qualified SEO Consultation
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0