close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Pretty URL with 2 variables

Thread began 9/18/2020 9:05 am by MagsW | Last modified 9/19/2020 2:15 pm by Ray Borduin | 23 views | 7 replies |

MagsW

Pretty URL with 2 variables

I'm in the process of rebuilding a couple of results/detail pages on ten of our client's websites. This is a 'people' page with a list of staff which then links through to a further details page. Currently the URL for the details page is as follows:

https://www.sitename.co.uk/people2?Name=firstname&Surname=surname

I'd really like to make the URLs SEO-friendly:

https://www.sitename.co.uk/firstname-surname

I found a Mod Rewrite generator here: https://www.generateit.net/mod-rewrite/ and it gave me the following htaccess code:

RewriteEngine On
RewriteRule ^([^-]*)-([^-]*)$ /people2?Name=$1&Surname=$2 [L]

I copied that into my very lengthy htaccess file and it didn't work - if I try to access the pretty link I just get a server error. I know this is really outwith your remit but thought you might know what I'm doing wrong as you're generally very knowledgeable? I've attached the text of the htaccess file for info - the new line is at the bottom.

Sign in to reply to this post

Ray BorduinWebAssist

Maybe try changing it to:
RewriteRule ^([^-]*)-([^-]*)$ /people2.php?Name=$1&Surname=$2 [L]

and move it up to right after this line:
RewriteRule ^ https://www.edinburghtherapy.co.uk%{REQUEST_URI} [NE,L,R]

Sign in to reply to this post
Did this help? Tips are appreciated...

MagsW

Sadly that didn't work - it actually redirected every link on the site to an empty people page!

Sign in to reply to this post

Ray BorduinWebAssist

If you give me FTP access and a sample url then I can take a look.

Sign in to reply to this post
Did this help? Tips are appreciated...

MagsW

That would be great - details in PM.

Sign in to reply to this post

Ray BorduinWebAssist

The issue is that you have some pages or folder names with dashes... so it can't tell if it is a first and last name, or one of your existing pages.

I updated the mod rule to use double dash between the name and that seems to work:

Sign in to reply to this post
Did this help? Tips are appreciated...

MagsW

That's fantastic thanks, it put me on the right path. I've amended it further because a few people had hyphenated surnames, so I changed the delimiter to an underscore. It now reads as follows:

RewriteRule ^people/([^_]*)_([^_]*)$ /people2?Name=$1&Surname=$2 [L]

which gives the following URL:

https://www.mydomain.co.uk/people/Name_Surname

I would like to take this one step further as some people have double-barrelled names with spaces, for example:

https://www.mydomain.co.uk/people/Leonardo_Da%20Vinci

should be

https://www.mydomain.co.uk/people/Leonardo_Da_Vinci

I used a str_replace in the URL on the results page like this:

a href="/people/<?php echo str_replace(“ “, ”_”, ($rsPractitioners->getColumnVal("Name"))); ?>_<?php echo str_replace( " ", "_", ($rsPractitioners->getColumnVal("Surname"))); ?>>"

However I can’t figure out how to alter the recordset on the details page to accommodate this.

<?php
$rsPractitioners = new WA_MySQLi_RS("rsPractitioners",$PowerCMSConnection_i,1);
$rsPractitioners->setQuery("SELECT * FROM practitioners WHERE practitioners.Name = ? AND practitioners.Surname = ?");
$rsPractitioners->bindParam("s", "".$_GET ['Name'] ."", "-1"); //ParamName
$rsPractitioners->bindParam("s", "".$_GET ['Surname'] ."", "-1"); //ParamSurname
$rsPractitioners->execute();
?>

I tried the following but it doesn’t work:

<?php
$rsPractitioners = new WA_MySQLi_RS("rsPractitioners",$PowerCMSConnection_i,1);
$rsPractitioners->setQuery("SELECT * FROM practitioners WHERE practitioners.Name = ? AND practitioners.Surname = ?");
$rsPractitioners->bindParam("s", "". str_replace(" ", "_", "$_GET ['Name']") ."", "-1"); //ParamName
$rsPractitioners->bindParam("s", "". str_replace(" ", "_", "$_GET ['Surname']") ."", "-1"); //ParamSurname
$rsPractitioners->execute();
?>

Sign in to reply to this post

Ray BorduinWebAssist

You are separating with an underscore, so it isn't going to work if the first name has a space. However it should work with the last name. You would have to change your htaccess rule to:

RewriteRule ^people/([^_]*)_([^\/]*)$ /people2?Name=$1&Surname=$2 [L]

Then your recordset parameters would be:
$rsPractitioners->bindParam("s", "". $_GET ['Name'] ."", "-1"); //ParamName
$rsPractitioners->bindParam("s", "". str_replace("_", " ", $_GET ['Surname']) ."", "-1"); //ParamSurname

Sign in to reply to this post
Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...