This forum has been moved here:
Helicon Tech Community Forum

ISAPI_Rewrite 3.0 (Forum Locked Forum Locked)
 Helicon Tech : ISAPI_Rewrite 3.0
Subject Topic: Trailing slash question
Author
Message |
timfel
Newbie


Joined: 02 August 2007
Posts: 10
Posted: 14 September 2011 at 5:19am

Hello,

I'm struggling with a trailing slash problem that should be straightforward but isn't! I've tried lots of things that haven't worked so it's not worth listing them here.

I have a search function on my website that reads the search query as a URL parameter. I have a rewrite rule in place that pretties this up as below:

#  rewrite /search/ipod/ to /search.php?s=ipod
RewriteRule ^/search/(.+)/$ /search.php?s=$1

So if I go to the URL www.example.com/search/ipod/ it correctly takes me to  /search.php?s=ipod

This all works fine. My problem is I want the rewrite to work both with and without the trailing slash. I want the trailing slash to be added only to URLs that start with /search as all the other URLs go to files.

As I say, I've tried various methods and none have worked. The most likely seemed to be simply to make the / in the matching part optional with a ? but this then passed the / through as part of the keyword (e.g. s=ipod/).

Any ideas?

TIA

Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 14 September 2011 at 5:40am

Hello TIA,

Try using the following:

Code:
RewriteRule ^/search/([^/]+)/?$ /search.php?s=$1


Regards
Andrew
Back to Top
 
timfel
Newbie


Joined: 02 August 2007
Posts: 10
Posted: 14 September 2011 at 5:52am

Wow, very quick and that worked - thanks Andrew!

That solved my problem but I'm just wondering if I should address the canonical URL/duplicate content problem whilst I am at it?

Is there a way to make it change the url so it always has a trailing slash even if the user doesn't type it, so that the search engines don't see two pages (one with the trailing slash and one without)?

Thanks again!
Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 14 September 2011 at 6:08am

In examples section you'll find the solution to trailing slash issue.
Search engine sees 2 pages only if you have 2 types of links in your web-site code, if its only one - no problrm must occur.

Regards
Andrew
Back to Top
 
timfel
Newbie


Joined: 02 August 2007
Posts: 10
Posted: 14 September 2011 at 6:47am

Thanks Andrew,

Can't actually see it in the examples section I'm afraid.

My site only contains links to the URL with the slash but I've noticed that other sites pick up links to my site and somehow manage to drop the slash so both pages are out there.

Just want to make the page always appear with the slash.

Thanks.
Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 14 September 2011 at 7:28am

Try using:

Code:
#Fix missing trailing slash char on folders
RewriteRule ^([^.?]+[^.?/])$ $1/ [NC,R=301,L]
Back to Top
 

Sorry, you can NOT post a reply.
This forum has been locked by a forum administrator.

Printable version Printable version