close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

URL Rewrites

Thread began 11/15/2013 7:59 am by iainmacdonald331081 | Last modified 11/16/2013 2:59 am by iainmacdonald331081 | 3492 views | 8 replies |

iainmacdonald331081

URL Rewrites

I've just been having a look at this, and have gotten halfway to what I would like to do.

So I've got it working by changing my .htaccess file to include:

Options +FollowSymLinks
RewriteEngine on
RewriteRule index/LodgeID/(.*)/ index.php?LodgeID=$1
RewriteRule index/LodgeID/(.*) index.php?LodgeID=$1



Which is rewriting:

http://lodges.goodsafariguide.com/lodgedetails/index.php?LodgeID=288

To:

http://lodges.goodsafariguide.com/lodgedetails/index/LodgeID/288/

And I've resolved the issue of my paths to images and CSS files going AWOL.

What I would like to be able to do is include a variant of the lodge name in the URL.

I do have a field in the lodges table which has a short name string which could be used, e.g.:

africanhorsebacksafaris

Is it possible to use rewrite the URL to:

http://lodges.goodsafariguide.com/lodgename/

Where 'lodgename' is stored as a field in the same lodges table as LodgeID?

Sign in to reply to this post

Jason ByrnesWebAssist

yes, you could do that, you would then need to edit the recordset on the page to filter using the lodge name column instead of the ID column.

Sign in to reply to this post

iainmacdonald331081

Thanks Jason - I may have been overthinking it.

At the moment the recordset is:

SELECT *
FROM lodges
WHERE LodgeID=ParamLodgeID

Where ParamLodgeID is:

Type: Integer
Default Value: -1
Run-time Value: $_GET['LodgeID']

So I changed the recordset to:

SELECT *
FROM lodges
WHERE Lodge=ParamLodgename

Type: Text
Default Value: -1
Run-time Value: $_GET['Lodgename']

It was a case of sucking it to see, but I wasn't sure about the default value being -1 for text rather than an integer.

And I added:

RewriteRule index/GSG_URL/(.*)/ index.php?GSG_URL=$1
RewriteRule index/GSG_URL/(.*) index.php?GSG_URL=$1
RewriteRule index/(.*)/ index.php?GSG_URL=$1
RewriteRule index/(.*) index.php?GSG_URL=$1



to the .htaccess file.

And that gives me:

http://lodges.goodsafariguide.com/lodgedetails/index/GSG_URL/africanhorseback/

and

http://lodges.goodsafariguide.com/lodgedetails/index/africanhorseback/

I tried:

RewriteRule (.*)/ index.php?GSG_URL=$1
RewriteRule (.*) index.php?GSG_URL=$1



To get to:

http://lodges.goodsafariguide.com/lodgedetails/africanhorseback/

But it didn't like that, and didn't show any data.

Is there a tweak in the syntax, or does it always need to reference the .php page?

Sign in to reply to this post

Jason ByrnesWebAssist

so the URL perameter you are passing to the recordset is Lodgename. your URLS should look like this:

http://lodges.goodsafariguide.com/lodgedetails/index/Lodgename/africanhorseback/

and the rewrite rule should be:

Options +FollowSymLinks
RewriteEngine on
RewriteRule index/Lodgename/(.*)/ index.php?Lodgename=$1
RewriteRule index/Lodgename/(.*) index.php?Lodgename=$1

Sign in to reply to this post

iainmacdonald331081

Sorry Jason - my fault. In my first post I said Lodgename, but when i looked at it I realised the field was called 'GSG_URL'.

So:

RewriteRule index/GSG_URL/(.*)/ index.php?GSG_URL=$1
RewriteRule index/GSG_URL/(.*) index.php?GSG_URL=$1

Gets me to:

http://lodges.goodsafariguide.com/lodgedetails/index/GSG_URL/africanhorsebacksafaris/

And

RewriteRule index/(.*)/ index.php?GSG_URL=$1
RewriteRule index/(.*) index.php?GSG_URL=$1

Gets me to:

http://lodges.goodsafariguide.com/lodgedetails/index/africanhorsebacksafaris/

But is it possible to get to:

Gets me to:

http://lodges.goodsafariguide.com/lodgedetails/africanhorsebacksafaris/

Or does it always need to include the page itself (e.g. index)?

Sign in to reply to this post

Jason ByrnesWebAssist

I'll be 100% honest, Mod Rewrite is not my specialty. I'm sure it is possible to not include the page itself, but I am not sure on the syntax.

Sign in to reply to this post

iainmacdonald331081

No worries Jason. You got me on the right track though - I always just assumed using the ID was the best variable to pass.

But presumably there's no harm in passing another one.

The thing to check would just be to make sure that that field was always unique, which can be done using some validation when its entered?

As long as that's done it should be good to go.

Sign in to reply to this post

Jason ByrnesWebAssist

yup, that is correct.

you should also ensure that the field being used only contains URL safe alpha numeric characters.

also, a good rule of thumb is to force any spaces to use hyphens instead:
this-is-my-lodge

Sign in to reply to this post

iainmacdonald331081

Just to say I got this all working with:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/ index.php?GSG_URL=$1
Sign in to reply to this post

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...