Forum
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
Do you mean the other way around?
should be rewritten to:
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
Ok, so you have this in the browser's location bar:
and you want that URL to be served by the underlying file
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?
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
Ok, so you want to rewrite this in the location bar
to this underlying URL
The problem there is whatever rule matches
my-post.php
will also matchpost.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?
It's not the word
post
specifically - it's that the pattern to match your slug would also match the rewritten URL.