Jump to content

Cre8asiteforums Internet Marketing
and Conversion Web Design


Photo

Url Rewrite Help Needed


  • Please log in to reply
13 replies to this topic

#1 DonnaFontenot

DonnaFontenot

    Peacekeeper Administrator

  • Site Administrators
  • 3813 posts

Posted 24 February 2012 - 04:22 PM

I'm working on a major conversion project (from one cms to wp) in which the client needs the url structure to remain the same for the existing pages that I will be importing (new pages don't need and shouldn't have this done to them).

So, let's say the urls are like this (about 1,000 total):

http://www.somedomai...05/somepage.htm
http://www.somedomai.../2387/apage.htm

In all cases, the http://www.somedomain.com/pages remains the same.

I want to import the content that will create urls like this:

http://www.somedomain.com/somepage/
http://www.somedomain.com/apage/

That's the easy part.

Now, I need to do three things to rewrite these urls so they match the original structure.

1. add /pages/ after http://www.somedomain.com for all the urls in this list (not all new urls going forward, just this initial list of 1000 or so)

2. add the number between pages/ and the pagename, with each number being unique to the pagename, so i'll need to manually type all 1000 or so in.

3. remove the trailing / and add the .htm to the end (again, only to this list of 1000 or so, not all future urls)

Any thoughts on how to write the URL rewrite code to make this happen? I'm brain dead on this matter, and just can't seem to wrap my head around it. All help appreciated.

Hope I was clear. No guarantees on that. :)

dd

#2 cre8pc

cre8pc

    Dream Catcher Forums Founder

  • Admin - Top Level
  • 13550 posts

Posted 25 February 2012 - 08:15 PM

Well...I guess you win the award for stumping everybody! I can vouch that Eric saw your questions but didn't think he was qualified to help because he thought he needed more experience with WP.

:dazed:

#3 iamlost

iamlost

    The Wind Master

  • Site Administrators
  • 4621 posts

Posted 25 February 2012 - 10:44 PM

OK, I've read the OP a number of times and I'm not certain that I understand...

Are these imported pages existing ones that will require 301s to pass through existing values?
Why does importing the URLs change the name from, i.e. http://www.somedomai...05/somepage.htm to http://www.somedomain.com/somepage/ ?

Colour me confused.

If 301s are not required then I'd run the files names through a script that restructures/names as wanted then upload already corrected. But if this is impractical for whatever reason...???

Edited by iamlost, 25 February 2012 - 10:45 PM.


#4 DonnaFontenot

DonnaFontenot

    Peacekeeper Administrator

  • Site Administrators
  • 3813 posts

Posted 25 February 2012 - 10:57 PM

Well, I don't know how to explain why the import process doesn't add the appropriate url folder info - It just doesn't. Nothing I do beforehand will change that, afaik. And I've even tried manually changing the wordpress post slug to add in the /pages/12345/ portion before the postname in the url, but wordpress simply strips the slashes and makes the slug pages12345postname instead. So even if I wanted to manually change 1000 slugs, it wouldn't work. So that's why I was assuming that what I need to do is handle it via URL Rewrite in the .htaccess. Make sense?

#5 iamlost

iamlost

    The Wind Master

  • Site Administrators
  • 4621 posts

Posted 26 February 2012 - 10:14 AM

Ouch!
The numbering part is the kicker in the 'easy:hard' ointment: can it be sequential? Like starting at 2225 and going to 3224 (if a thousand pages) or are the numebers specific and out of sequence? Does it matter which number gets stuck to which page? If so can you import them in the wanted order?

#6 DonnaFontenot

DonnaFontenot

    Peacekeeper Administrator

  • Site Administrators
  • 3813 posts

Posted 26 February 2012 - 12:19 PM

It cannot be sequential or randomly assigned. It does matter which number gets stuck to which page, and it's not a perfect sequence. So there are gaps between numbers. I'm willing to create a full list of all 1000+ pages in htaccess. So if I can just figure out the basic formula for adding the pages/12345 portion up front and the .htm portion at the back, I can start constructing the list of rewrites.

If all else fails, I'll tell the client he has absolutely no choice but to accept that the urls will not remain the same, and he'll have to settle for 301 redirects, but I know he's going to go postal if I tell him that. So, I'd rather find the help of a url rewrite guru if at all possible first.

#7 jonbey

jonbey

    Eyes Like Hawk Moderator

  • Moderators
  • 4396 posts

Posted 26 February 2012 - 05:09 PM

Is it possible to split each directory part out into seperate columns in the spreadsheet and then delete out the number one? Then a few find and replace commands should sort the rest out?

#8 DonnaFontenot

DonnaFontenot

    Peacekeeper Administrator

  • Site Administrators
  • 3813 posts

Posted 26 February 2012 - 06:20 PM

Not sure I get what you're saying, Jon.

#9 iamlost

iamlost

    The Wind Master

  • Site Administrators
  • 4621 posts

Posted 26 February 2012 - 09:21 PM

OK...Maybe :)

Give this a try:

RewriteRule ^/somepage/$ http://www.somedomain.com/pages/200005/somepage.htm?  [R=301,L]
Note: replace 'somepage' in both instances with appropriate name; replace numerical directory with appropriate number.

Let me know how/if works.

#10 DonnaFontenot

DonnaFontenot

    Peacekeeper Administrator

  • Site Administrators
  • 3813 posts

Posted 26 February 2012 - 09:47 PM

Thanks! I'll try that tomorrow and let you know.

#11 iamlost

iamlost

    The Wind Master

  • Site Administrators
  • 4621 posts

Posted 27 February 2012 - 08:11 AM

Woke up knowing I'd gone way wrong...

The above code won't help, if I understand your problem, because it will be attempting to redirect to a non-existent URL.
The import creates /somepage/ . That will exist. Simply pointing/redirecting users to where you would like it to be instead won't fly.
Given the numbering problem I see the options as either:
* manually changing each imported directory URL to the desired page URL.
* downloading page content then uploading to desired page URLs.
* possibly using htaccess alias to rename each internally.

I have meetings for the first part of this morning so can't look at this again until later if it remains unsolved.
Note: that won't actually 'move' the content.

#12 DonnaFontenot

DonnaFontenot

    Peacekeeper Administrator

  • Site Administrators
  • 3813 posts

Posted 27 February 2012 - 09:37 AM

Keep in mind that with WP, these things don't "exist" anyway in an actual folder structure anyway. It's all just content in a database and the url is pretty much bogus to begin with. But you're right, in that if someone links to the url, then WordPress would sure as heck need to know where it refers to.

I don't know. At this point, I'm not sure this is possible at all.

#13 DonnaFontenot

DonnaFontenot

    Peacekeeper Administrator

  • Site Administrators
  • 3813 posts

Posted 27 February 2012 - 09:50 AM

I just had a thought, and since I've just woken up, it may be a ridiculous one, but I'll document it here before I forget it anyway.

What if I simply made a Pages category, with a thousand child categories, each one being the 12345 part?

Then, once I import all 1000 posts, I can just go assign each one to the child subcat (the number), and if the permalink structure is /%category%/%postname%/, then that should assign it /pages/12345/posttitle, i think.

In fact, I could add the .htm there too = /%category%/%postname.htm%/

Any new posts could just be assigned to a different category that has nothing to do with the Pages category if he'd like.

That might work if all the imports are imported as posts and not pages. That wasn't how I'd planned to do it, but it might be how I plan to do it now. :)

Ok, off to get coffee in me, and revisit this when the brain is awake.

#14 Michael_Martinez

Michael_Martinez

    Time Traveler Member

  • 1000 Post Club
  • 1354 posts

Posted 27 February 2012 - 05:41 PM

What if I simply made a Pages category, with a thousand child categories, each one being the 12345 part?

Then, once I import all 1000 posts, I can just go assign each one to the child subcat (the number), and if the permalink structure is /%category%/%postname%/, then that should assign it /pages/12345/posttitle, i think.


That's how I probably would have done it.

I wonder, though, if you could not have used hyphens in the slugs and then used a rewrite rule to convert slashes to hyphens.



RSS Feed

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users