Forum

Thread tagged as: Configuration, Hosting, Blog

Blog url rewrite question

I've done some reading on this subject (Perch docs, 24Ways article by Drew) but I'm not sure whether the following is possible, would appreciate any comments....

Can I take the blog uri, e.g. https://www.my-site.com/blog/post.php?s=2015-10-07-my-post

and use rewrite rules to arrive at:

https://www.my-site.com/blog/my-post.php

Thanks

Nigel Harding

Nigel Harding 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you mean the other way around?

 https://www.my-site.com/blog/my-post.php

should be rewritten to:

 https://www.my-site.com/blog/post.php?s=2015-10-07-my-post

That's going to be hard to do, as the rewritten URL contains information not in the original - namely the date. To get that result, you'll need to change your blog slug format to not include the date.

No, I want to replace the slug info in the original path and end up with my-post.php

I can see that you would remove the date using "Slug format" in perch - just use {postTitle}

Then I guess the perch path to the blog page would be /blog/{postSlug}.php

But I'm not sure if you can or how you would rewrite the url in .htaccess to take it from https://www.my-site.com/blog/post.php?s=2015-10-07-my-post to result in https://www.my-site.com/blog/my-post.php

Does that make sense?

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so you have this in the browser's location bar:

  https://www.my-site.com/blog/post.php?s=2015-10-07-my-post

and you want that URL to be served by the underlying file

 https://www.my-site.com/blog/my-post.php

That doesn't sound like you're using Perch, so I'm not sure this is the place to ask.

Yes I'm using Perch, here is the site: https://www.takeonetv.com/blog/index.php

The real uri of my test post is: https://www.takeonetv.com/blog/post.php?s=test-post

I'd like to know if this can be rewritten and used in Perch as https://www.takeonetv.com/blog/test-post.php or is the slug always needed as part of the uri?

Ben Furfie

Ben Furfie 3 points
Registered Developer

Nigel. Is the URL of this site (which is using Perch Blog) what you're trying to achieve?

https://dvnw.co.uk/news/this-is-a-test-post

Yes Ben, something like that

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so you want to rewrite this in the location bar

https://www.my-site.com/blog/my-post.php

to this underlying URL

https://www.my-site.com/blog/post.php?s=my-post

The problem there is whatever rule matches my-post.php will also match post.php and send you around in a loop.

OK, so I see that using "post" in the blog title would be a no-no, but otherwise (providing that we avoid using "post" in the blog title) it could be done?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's not the word post specifically - it's that the pattern to match your slug would also match the rewritten URL.