Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

This issue is on Wordpress site.

I am aware we can change the URL naming convention in WP but i have changed my url format from date format to simple postname followed by slug as shown below.

old style

(www.domain.com/2013/02/09/rin​gdroid)

new style

(www.domain.com/rin​gdroid)

Google previously indexed my websites pages (sitemap.xml) with below format:

www.domain.com/2013/04/18/hot​test-gadgets-of-2013-to-include-in-​your-list
www.domain.com/2013/02/09/rin​gdroid

I have resubmitted the sitemap but there are still 404 errors in Google/Bing engine.

Could you please help me to write 301 redirects rule in .htaccess file so when some clicks the URL for:

www.domain.com/2013/02/09/rin​gdroid

They should be redirected to:

www.domain.com/rin​gdroid

How we can write rule in .htaccess file to remove date part 2013/02/09/?

I tried something like this (Googled it ), but didnt worked

RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d

share|improve this question
    
What have you tried? –  John Conde Jun 28 '13 at 12:14
add comment

2 Answers

RewriteEngine On

RewriteBase /

RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$4 [R=301,NC,L]

share|improve this answer
add comment
RewriteEngine On
RewriteRule ^(\d+/){3}(.*)$ /$2 [R=301]

This will strip any sequence of 3 numbers each followed by slashes (so it will work with short year dates like YY/MM/DD dates or single digit days/months like 2013/2/9. If you want to keep the date in the url and have it silently redirect to the correct page without the user knowing, lose the [R=301]

share|improve this answer
    
also, is this for a wordpress site? If so it would be better to manage your url naming within the wordpress options than to go writing your own htaccess rules. –  WebChemist Jun 28 '13 at 10:09
1  
Hi WebChemist , Really thankful giving an idea how to implement it. I tried your suggestion but Url its was returning as www.domain.com/ringdroid/02/09/rin​gdroid. so i have implemented my below own code and here it is. –  user2131844 Jun 29 '13 at 0:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.