Trouble with redirects

Hello, I’m trying to get my Ghost installation to redirect all traffic from

/post/yyyy/mm/dd/post-name.aspx

to

/post-name/

i.e. the default way Ghost creates URLs for posts. I’m using the redirects feature under the Labs panel for this. My redirects.json file looks like this

[{ "from":"/post/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*).aspx", "to":"/$1/" }]

Which should work. The redirects file uploads fine. However whenever i test the redirection, by going to http://blogname.com/post/yyyy/mm/dd/post-name.aspx, I just get 302 Forbidden returned.

What am I doing wrong?

Thanks, Dan

“302 Forbidden” isn’t a status code… 302 is a temporary redirect, 403 is Forbidden. Not sure what you’ve got going on here. It sounds like something not to do with Ghost is getting in the way.

Your regex looks OK, although I think you may need to escape the slashes and the second dot:

https://docs.ghost.org/docs/redirects

(I’ve not tested, but the docs show everything escaped)

If you post your real URL someone can have a look to see if they can suggest what it might be from the headers. Otherwise please post the full headers from curl -I <your real blog post url>.

Hi Hannah,

Apologies - I did mean 403 Forbidden, not 302. 302 is what I was hoping to see. No problem escaping the slashes, but if I upload this redirect

[{
“from”:"^/post/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*).aspx",
“to”:"/$1/",“permanent”: true
}]

The redirect fails to upload saying “Could not parse JSON: Unexpected token . in JSON at position 54.” which is me escaping the . before aspx.

For reference, I am trying to get a redirect from a post like blog.hmobius.com/post/2000/09/19/off-at-last.aspx to blog.hmobius.com/off-at-last

This is the output from the curl command. (forum only allows me to post two URLs per post, hence separate output)

curl -I http://blog.hmobius.com/post/2000/09/19/off-at-last.aspx
HTTP/1.1 403 Forbidden
Date: Wed, 11 Apr 2018 18:20:06 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Set-Cookie: __cfduid=d240d0b3191f71a94451d89bad60a739f1523470806; expires=Thu, 11-Apr-19 18:20:06 GMT; path=/; domain=.blog.hmobius.com; HttpOnly
Cf-Railgun: 150494bece stream 0.000000 0200 e6be
Server: cloudflare
CF-RAY: 409f771ab6b90cd7-LHR

You will need to use double backslashes to escape a regex in JSON exactly as shown in the docs:

[{
“from”:"^\\/post\\/[0-9]{4}\\/[0-9]{2}\\/[0-9]{2}\\/(.*)\\.aspx",
“to”:"/$1/",“permanent”: true
}]

Not sure if you’ve tried that.

However, you’re getting a 403 before you hit Ghost here, and I can see you’re a Ghost(Pro) customer.

If you’re having any issue with a Ghost(Pro) site, please drop us an email on support@ghost.org and we’ll be more than happy to give you a hand directly :slight_smile: