Forum

Thread tagged as: Question, Blog

URL Rewriting

Hello,

I've spent the last 3 hours attempting to get this to work with the plethora of threads created to no avail.

My setup

  • post.php is in a folder called blog
  • in my .htaccess file i have
RewriteRule ^/blog/([a-zA-Z0-9-]+)$ /blog/post.php?s=$1 [L]
  • in the perch setup area i have
/blog/{postSlug}

The result is a 404 error.

Diagnostic Report


Perch: 2.8.31, PHP: 5.6.25, MySQL: 5.5.32, with PDO Server OS: Linux, cgi-fcgi Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_blog (5.0) App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', ); PERCH_LOGINPATH: /perch PERCH_PATH: /home/beecrown/public_html/perch PERCH_CORE: /home/beecrown/public_html/perch/core PERCH_RESFILEPATH: /home/beecrown/public_html/perch/resources Image manipulation: GD PHP limits: Max upload 128M, Max POST 128M, Memory: 768M, Total max file upload: 128M F1: 2edba60ed1f613d6dd804feb202456a2 Resource folder writeable: Yes HTTP_HOST: beecrowned.com DOCUMENT_ROOT: /home/beecrown/public_html REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Really sorry to raise this again, I'm just not sure what else to try.

Chima Nwosu

Chima Nwosu 0 points

  • 5 years ago
Simon Clay

Simon Clay 127 points

Hi Chirma, can you give an example of a yellow that is resulting in a 404?

Hi Simon, thank you for your assistance.

Do you mean url? This is what it looks like https://myurl.com/blog/2016-08-18-test

Simon Clay

Simon Clay 127 points

Thanks, yes, lol I meant URL.

Does it work if you go to: https://myurl.com/blog/post.php?s=2016-08-18-test ?

No it doesn't, all the posts result in an errror

Rachel Andrew

Rachel Andrew 394 points
Perch Support

What is the error? Is that also a 404?

If so, have you created your post page at that location?

it's 404 not found and yeah, post.php is within a folder called blog (screenshot https://prnt.sc/cgdgy0) and the rest of my perch files are on the root (screenshot here https://prnt.sc/cgdgr0)

Drew McLellan

Drew McLellan 2638 points
Perch Support

If the file is there, but /blog/post.php gives you a 404 then you have a server issue unrelated to Perch.

Ahhh - i will have a talk with my host then. Thanks Drew

Hello,

So I've had a chat with my host and mod_rewrite is enabled. I've also been able to rewrite my extenstions using the below from your documentation:

# Redirect to PHP if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+)$ $1.php [L,QSA]

However, the below still doesn't work

RewriteEngine On
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]

Any ideas?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

If you are getting a 404 then as Drew explained it isn't getting as far as Perch, so there isn't a lot I can suggest.

I can access https://beecrowned.com/blog/post.php perfectly just not any of the posts but thank you for the help. I'm going to try a fresh install on a new server.

Hello,

I thought I'd provide an update on how I got on. I was able to get this working by resinstalling perch on the same server and adding this:

RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]

To the htaccess file. However, this line isn't working as it should:

RewriteRule ^blog/category/([a-zA-Z0-9-/]+)$ /blog/archive.php?cat=$1 [L]

It displays the page but doesn't display my perch content nor does it render my css file or images so i'm guessing that my RewriteRule is rewriting the path to all my filles outside of the /blog/ folder.

I've amended my category_link.html file to read

<a href="/blog/category/<perch:category id="catSlug" />">

any ideas?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Our supported solution for URL rewriting is using Routes in Perch Runway, so I've not got any suggestions at this point.