Jump to content

Recommended Posts

Posted

I'm just updating my PHP knowledge and have come up against a problem.

 

I've always programmed in PHP, passing variables to the php page like this.

 

http://www.testshop/product.php?id=278645

 

But how do I do this?

 

http://www.testshop.com/278645

 

I see most on-line sites now do it this way, but I have no idea what technique they are using. Some shops even have the description in the URL as well for better SEO. A Google search has been fruitless so far :(

Posted

This is done with a .htaccess file. Create a file called .htaccess on your root(index) directory and paste this:

 

RewriteEngine on

RewriteRule ^view/([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^contact index.php?page=contact

# 404 - Retains folder name, so /abcd displays 404.php content without forwarding to 404.php
ErrorDocument 404 /404.php

  • Thanks 1
Posted
Also regarding 'description in the URL', as long as you call $_POST["id"], the following text (...-CandyBar-40p) I BELIEVE will be ignored. Don't trust me on this, test it. But I know it works in some way.
Posted (edited)

I'm using IIS, is there an equivalent?

 

Also how would I do it like this?

 

http://www.testshop.com/278645/This_is_product_Description

Edited by zag
  • 3 weeks later...
Posted
One thing I did notice that was all the relative links got broken. But I simple added a slash to the beginning of the image, link and css includes and it works again.

 

This all depends on the file location. This caught me out at first too.

 

Just remember that if you are in /include/hello/hello.html, you would normally include a file depending on the current location (say, notice.php in your root directory - /../../notice.php). Now you are using rewrite, your browser will think you are in a physical location (/hello/), and any links to other resources need to change accordingly. This will in hand cause problems for anyone who uses the ?artist.php?i=... option,so make sure none of your links are broken!

 

The way I keep my code straight-forward is by using PHP's document_root, for example require($_SERVER["DOCUMENT_ROOT"]."/site/functions.php"). This way you are only working forward and not back!

 

I know you're writing in ASP but this might be helpful (or to anyone else)!

Posted

Yeh I was actually using PHP, works brilliantly.

 

I've even done a name search function so I can get the entire artist name in the URL now. Works really well for search engines.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...