Forum

Thread tagged as: Question, Problem

List and Detail URL Rewriting

Hi,

I've got a list and detail page at the moment but cannot seem to get the URL to rewrite using .htaccess.

At the minute I have this code within my .htaccess.... RewriteRule ^windows/([a-zA-Z0-9-/]+)$ /windows?s=$1 [L]

And the link within the list template is... <a href="/<perch:content id="slug" type="slug" />">

Could any body shed some light on where I am going wrong here? Also, what would be the best way of getting the rewrite into the Title tag?

Thanks for your help

Curtiss Greveson

Curtiss Greveson 0 points

  • 6 years ago

Does changing the link to this help?:

<a href="/windows/<perch:content id="slug" type="slug" />">

Martin Underhill said:

Does changing the link to this help?:

<a href="/windows/<perch:content id="slug" type="slug" />">

Unfortunately not, it brings me back a 500 Internal Server Error

Hmmm… Thought it'd be the directory thing. I'm clutching at straws now… :P

Did you include this before the rewrite rule: RewriteEngine On

Martin Underhill said:

Hmmm… Thought it'd be the directory thing. I'm clutching at straws now… :P

Did you include this before the rewrite rule: RewriteEngine On

Yeah it's thrown me too!

The RewriteEngine On is at the top of the .htaccess file too

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is the issue the link being wrong or the URL not rewriting to the correct file?

Hi Drew,

The issue is the rewriting - if I leave everything as it was when I first set it up I could access the detail page

Drew McLellan

Drew McLellan 2638 points
Perch Support

What error are you getting at the moment? Have you checked your server error logs for the message?

I'm not getting any errors as such just a page not found

Drew McLellan

Drew McLellan 2638 points
Perch Support

A 404 status code?

Yes that's correct

Drew McLellan

Drew McLellan 2638 points
Perch Support

Does /windows?s=$1 exist? I seems like it should be /windows/index.php?s=$1 or similar.

Wouldn't /windows/index.php?s=$1 mean that the page is placed within the folder 'windows' though? Was trying to keep all files within the root of server

Maybe this would do it, in that case: ^windows/([a-zA-Z0-9-/]+)$ /windows.php?s=$1 [L]

Unfortunately that doesn't work either. I will have to look into alternative ways of doing this

Drew McLellan

Drew McLellan 2638 points
Perch Support

Where is the file? Is it /windows.php ?

I'm sure it's simple to fix, but you're not sharing much information to enable us to help you well.

I have a page called windows.php which is in the route - this is also using a rewrite to remove the .php off the end of the address.

I then have a list and detail page of which the list page looks like the following...

    <div class="col30">
        <a href="/<perch:content id="slug" type="slug" />">
            <img src="<perch:content id="product-image" label="Product Image" type="image" width="350" height="210" crop="true" />" />
            <h3><center><perch:content id="product-title" label="Product Title" type="text" /></center></h3>
        </a>
    </div>

As well as the list my .htaccess reads the following...

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=permanent,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]

RewriteCond %{REQUEST_URI} !^/?(admin|user)/

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


ErrorDocument 404 /not-found/

The end result should be that I click onto the link within the list and then the detail page should come up as the folllowing...

'website.co.uk/[slug]' instead of the current 'website.co.uk/windows?s=$1'

Try putting RewriteRule ^/([a-zA-Z0-9-/]+)$ /windows.php?s=$1 [L] just after the RewriteEngine On line. If that doesn't work, move it down a line, try it and keep doing that. I suspect it's because there's no file called windows.php because the .php bit is being removed further up the file. Worth a shot :)

Still getting nothing from that unfortunately.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try moving it up to just below your RewriteEngine On statement. The rules match in order.

That doesn't seem to solve the problem either.

I have tried both windows and windows.php in the following...

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/([a-zA-Z0-9-/]+)$ /windows?s=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=permanent,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]

RewriteCond %{REQUEST_URI} !^/?(admin|user)/

ErrorDocument 404 /not-found/