0

I'm trying to write a rule that when user types in this url:

domain.com/09/13/2013/thisIsMyPageTitle

That url stays in browser window, but content from this url is displayed:

domain.com/contentlibrary/thisIsMyPageTitle

This is my rule that I currently get an error with:

RewriteEngine On
RewriteRule ^((0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d[/])$(.*) /contentlibrary/$1  [L]

I'm trying to match the date with regular expression, and use the (.*) from the initial url in the second one that holds the content and actually exists.

2
  • 1
    I currently get an error with - Well don't make us beg... what is the error you are getting? Sep 18, 2013 at 19:01
  • Sorry I wasn't clear, it was an internal server error that displayed. Sep 18, 2013 at 19:25

2 Answers 2

3

If you're not going to do anything with date then why bother being precise with date semantics. You can simplify your regex:

RewriteRule ^[0-9]+/[0-9]+/[0-9]+/([^/]+)/?$ /contentlibrary/$1 [L]
1
  • 1
    Great way to move a Wordpress blog that used dates in the URL to one that no longer does. Thank you!
    – Ted Cahall
    Mar 18, 2018 at 16:52
0

The error that you're getting is probably because you have unescaped spaces in your regex. Specifically these:

[- /.]

The spaces get interpreted by mod_rewrite as the delimiter between parameters. Additionally, you have this:

$(.*)

at the end of your pattern. The $ matches the end of the string, so you want those swapped:

(.*)$

So:

^((0[1-9]|1[012])[-\ /.](0[1-9]|[12][0-9]|3[01])[-\ /.](19|20)\d\d[/])(.*)$

shold be the pattern that you want.

1
  • This answers my question the most complete so far... However one more point in the original question was that I desire the url with the date to remain in the browser window, and simply load the content from the url /contentLibrary Is mod_rewrite the correct tool to do this? I am most certain I have done this before similarly. Sep 18, 2013 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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