LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-23-2016, 09:03 AM   #1
socalheel
Member
 
Registered: Oct 2012
Location: Raleigh, NC
Distribution: CentOS / RHEL
Posts: 143

Rep: Reputation: 3
htaccess redirect ... regex help needed.


i am working on centos 6 box with apache only.

i need to set up an all encompassing redirect and i'm not sure how i can solve this one.

we recently rebuilt our company website. our old URL's are still indexed in google and do not map to our current URL structure.

our old URL structure had blog posts in subfolders according to the year and another subfolder for the month.

how can i construct a rule to basically remove the year and month subfolders and keep the requested page at the end?
example:

i need this:
Code:
www.mydomain.com/blog/2015/07/post-one/

to redirect to:
Code:
www.mydomain.com/blog/post-one/
 
Old 03-23-2016, 09:28 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,345
Blog Entries: 36

Rep: Reputation: Disabled
This isn't Wordpress-related is it?
 
Old 03-23-2016, 09:40 AM   #3
socalheel
Member
 
Registered: Oct 2012
Location: Raleigh, NC
Distribution: CentOS / RHEL
Posts: 143

Original Poster
Rep: Reputation: 3
it is ... i'd like to not install a plugin.

here is the rule i have so far:

Code:
redirect 302 ^/blog/[0-9]{4}/[0-9]{2}/(.*)$ /blog/$1
but isn't working for some reason.

i also tried this and it did not work:

Code:
RewriteRule ^/blog/[0-9]{4}/[0-9]{2}/(.*)$ /blog/$1 [R=302]

Last edited by socalheel; 03-23-2016 at 09:48 AM.
 
Old 03-23-2016, 10:41 AM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,345
Blog Entries: 36

Rep: Reputation: Disabled
Quote:
Originally Posted by socalheel View Post
Our old URL's are still indexed in google and do not map to our current URL structure.
So fix the URL structure on the new host to match the old?
I believe https://codex.wordpress.org/Using_Permalinks is what you are after.
It is not an addon, but a feature of Wordpress.

Have Fun!
 
Old 03-23-2016, 10:48 AM   #5
socalheel
Member
 
Registered: Oct 2012
Location: Raleigh, NC
Distribution: CentOS / RHEL
Posts: 143

Original Poster
Rep: Reputation: 3
thanks man ... our marketing team has pushed the decision to not use the year/month subfolders, so we don't want to match our old URL structure

i like that link you sent! thanks dude.

Last edited by socalheel; 03-23-2016 at 10:51 AM.
 
Old 03-23-2016, 11:26 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,345
Blog Entries: 36

Rep: Reputation: Disabled
So, what else is left?
 
Old 03-23-2016, 01:36 PM   #7
socalheel
Member
 
Registered: Oct 2012
Location: Raleigh, NC
Distribution: CentOS / RHEL
Posts: 143

Original Poster
Rep: Reputation: 3
i got a complete list of 404's from our marketing department and it wasn't that bad ... so i just did a few mins of text manipulating and wrote a few rewrite rules for those 404's.
 
Old 03-23-2016, 02:33 PM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,345
Blog Entries: 36

Rep: Reputation: Disabled
Quote:
Originally Posted by socalheel View Post
i got a complete list of 404's from our marketing department and it wasn't that bad
Funny how that works, sometimes, now isn't it?
 
Old 03-23-2016, 04:54 PM   #9
socalheel
Member
 
Registered: Oct 2012
Location: Raleigh, NC
Distribution: CentOS / RHEL
Posts: 143

Original Poster
Rep: Reputation: 3
haha yeah ... i was expecting 1,000 redirects or something.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why am I not able to redirect using htaccess. It says too many redirect rules. swathi.akkineni Linux - Newbie 1 07-31-2015 04:20 PM
htaccess rewriterule regex Eddie Adams Linux - Server 6 03-14-2011 06:29 PM
Redirect with htaccess chandranjoy Linux - Server 1 02-16-2011 08:40 AM
[SOLVED] Apache .htaccess redirection '?' (question mark character) using regex angel115 Linux - Software 2 11-05-2009 04:37 AM
Htaccess with a redirect Diode Linux - Networking 0 10-28-2003 07:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration