.htaccess redirect help


#1

need to code the following…

example.com/post/123456789/sample-post-here

to

example.com/sample-post-here

ive tried numerous redirects but haven’t found one that works


#2

Do you mean users will visit
example.com/sample-post-here
but be redirected to
example.com/post/123456789/sample-post-here


#3

No, I need users directed to the new slug:

example.com/sample-post-here


#4

Be warned that using permalinks of that format (with no post ID or date fragment) can have severe negative impacts on your blog’s performance, especially if you have many posts. See http://ottopress.com/2010/category-in-permalinks-considered-harmful/ for details.


#5

I’ve used this format and its been just fine. Many others do the same.

Sadly I still do not have an answer to my original question.


#6

You need to do this:

Redirect 301 /example.com/long-post/long-listing/post /example.com/to-short-post

so in your case add this to your .htaccess file

Redirect 301 example.com/post/123456789/sample-post-here example.com/sample-post-here

Notice the space between the two paths.


#7

That would work for one URL but I have hundreds

the numeric values and sample-post are always different


#8

ah. then you need some regular expressions included in there. That’s more complex but if you post 4 - 5 sample URLS i might be able to help you out. What type of site is this? (wordpress? joomla? drupal? phpbb? – your own?)…


#9

example.com/post/123456789/sample-post-here
example.com/post/2468379642/another-sample-post-here

The numbers are always different as is the end part of the slug

This is a wordpress site

Basically I want the old posts to transfer to the new format
example.com/sample-post-here

The numerical and post part of the slug removed


#10

The WordPress part is significant but in this case it doesn’t matter much. Did you get this resolved?

You have two options if you’re still looking for an answer. Install the plugin Redirection, and use the regex/regular expression option to describe your urls and explain what you want to do and the plugin will do it. The other more complex but “better” way of doing it is to edit your .htaccess to add your regex rules.

Regex is complicated but it allows you to target a lot of urls at once by making pattern-matching searches instead of specific urls. This could be a great starting point for you as they describe some of what I’m talking about towards the middle-bottom of the article. - http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html – And usually people hate this next link because it makes you think and you actually learn… but its one of the best regex resources out there - http://www.regular-expressions.info/

good luck.