Jump to content

Recommended Posts

I would decide a standard format for my URLs, and possibly consider developing - as scootstah pointed out - a router to handle any URL; although this isn't essential. I would then set-up the htaccess so my entire website can function with it - not just a single page. Finally, I would write the PHP code to handle each URL appropriately.

 

Like I said before, its not a simple case of "a section of htaccess code to make this happen" if you want it to work with the entire website, not just this page.

Thanks, but what do I need to do.  I dont know if I need to change my site, my database, my HT Access file or something else.

 

My links are either...

 

.com/siteinfo/contactus.php - to a standard page

 

.co,/products/roomproductscategorised.php?room=bedroom - a query for the database to return results.

 

When I search the internet all I find are guides on re-writing the HT Access file.  It doesn't say how my links should appear. 

That's because you need to decide how you want them to appear. No-one is going to tell you how to structure your URLs. It's up to you how you structure them and then think of a method to handle them...

 

If you write the htaccess file like

 

RewriteRule ^(.*)$ site.php?query=$1 [L]

 

It'll direct EVERYTHING to site.php and append a query variable. You then handle the $_GET['query'] how you want. E.g. you could have:

 

domain.com/products/categorise/bedroom/ translated into domain.com/site.php?query=products/categorise/bedroom

 

You then either have a router that handles the request or perhaps a simple switch loop which is just a way of handling the URL.

 

$query = explode('/' $_GET['query']);
switch($query[0]){
    case 'products':
        switch($query[1]){
            case 'categorise':
                // Do something here
            ...
        ...
    ...
}

 

I wouldn't say that's a particularly good design but you can see why its not a simple case of "what htaccess should I write for this". You have to understand what's happening and then how to proceed/handle what's going on.

Thanks, I had no idea I had to change the PHP on the pages.  This makes things very complicated.  I just thought I could change the HT file and it would read

 

website.com/products/roomproductscategorised.php?room=bedroom

 

and transfer it into something like

 

website.com/products/roomproductscategorised/bedroom

 

This makes it very complicated.  I have only been using PHP for 4 weeks. 

 

How long would you estimate it would take an experience PHP user to complete?

How long is a piece of string? The cleverer the system the long it'll take. On the flip side if no planning is done it could take a week (wouldn't call someone who doesn't plan a complex system experienced though).

 

Its perfectly do-able in a day, half day even. Don't forget your constructing the foundations of your application when doing something like this. A rickety foundation will result in an incomplete or bad system.

 

Attempting this with little experience might be a bad idea, but we learn from being thrown in the deep end and struggling to get out. Much of software design and development is done on paper, I don't know how complex your system is or what its for but even small systems should really have some planning involved.

F***ing hell.  I thought I just had to change the HT file.

 

Why is it when I search Google it comes with "simple" ways to change the HT access file.

 

Whats the difference between a "rickety foundation" and a solid foundation.  To me its just code which returns content from the DB.

A solid foundation is one that you can confidently build upon with ease and very little need - if any at all - to make changes.

 

A rickety foundation is one you have to tweak every time you add a piece of code just to make it work. After a while you'll realise selecting, inserting, updating and the rest are merely ways to manipulate data and interact with a databases. Doing that isn't necessarily "software development" its just a bit of coding.

 

Software development is more than just writing code. Its about drawing up a piece of software that works coherently with the clients needs and requirements using perhaps Data Flow Diagrams and Entity Relationship Models - not that everybody uses these as much work can be done by an experienced developer in their head.

 

"Software design is a process of problem solving and planning for a software solution. After the purpose and specifications of software are determined, software developers will design or employ designers to develop a plan for a solution. It includes low-level component and algorithm implementation issues as well as the architectural view." - Wikipedia

 

There are processes you follow in order to achieve a high end application; the Waterfall model (possibly considered outdated), Rapid Application Development (RAD) and the Spiral model are just some examples.

 

I'm fond of RAD and Incremental/Iterative design. Even with the knowledge I have, I consider myself a noob... some guys here are very clued up and have been studying it for years. I've been studying software development for 1 year amongst other things and been writing PHP for around 3 years - and just because I write PHP it doesn't mean I know how to develop a piece of software.

 

You sir, need to start reading!

What I dont understand is I cant get code to remove the ".php" from a link this .com/siteinfo/contactus.php but I cant get code to remove ".php?room=" from a link this "/products/roomproductscategorised.php?room=bedroom"

 

That what I thought I could do.

 

What's I've done this I cant start promoting my site.

Hi,

 

I tried the following code earlier and it no affect but I have retried and it works fine.

 

RewriteRule ^products/roomproductscategorised/([a-zA-Z-]+)$ /products/roomproductscategorised.php?room=$1

 

It converts

 

com/products/roomproductscategorised.php?room=bedroom

 

into

 

.com/products/roomproductscategorised/bedroom

 

However it changes the query links it produces on the page.

 

This

 

.com/products/roomproductscategorised.php/product.php?product_id=13702753

 

Should be:

 

.com/products/product.php?product_id=13702753

 

Can anyone advise what is causing this please? 

 

 

That's because its hard coded for "roomproductscategorised".

 

What your saying is wrong. It doesn't convert domain.com/products/roomproductscategorised.php?room=bedroom into domain.com/products/roomproductscategorised/bedroom. It works the other way around.

 

You aren't physically changing how to get to your files, your just allowing your website to accept nice - for want of a better word - URLs and then handling them using PHP to get the appropriate files based on the request.

 

 

RewriteRule ^products/roomproductscategorised/([a-zA-Z-]+)$ /products/roomproductscategorised.php?room=$1

 

The bold, italic section is why it wont work. Your converting every page that runs through your website to roomproductscategories.php; which is what I warned you about. As I explained previously, if you want to be able to create nice URLs for your entire website you must handle the URLs using a routing class/page or some other method in PHP...

 

I really don't know how else to explain this so you either find someone who can sit down and explain everything; hope someone replies who's more helpful then I appear to have been; or actually read a decent book and do some decent research on how to use htaccess with PHP to create nice URLs.

 

I don't mean to be rude but I've honestly tried my hardest.

You have been incredibly helpful.  Two days ago I didnt understand any of this and I think I have a 'working solution'.

 

It affects only query links and I have found a way around it.

 

Lets say someone clicks on  .com/products/roomproductscategorised/bedroom it takes them to roomproductscategorised.php which queries everything based on "bedroom".

 

If roomproductscategorised.php has only 2 links.  1 link is a standard link such as .com/siteinfo/contactus then it works fine and is unaffected. However if link 2 is .com/products/product.php?product_id=327288 then it changes it to .com/products/roomproductscategorised/product.php?product_id=327288 but if I add the full domain name in front of it then it doesn't add the roomproductscategorised

 

Its not ideal but its a 'working solution'.  If I make some money from my site then I will pay a professional to getting it working properly.

 

But using this method allows me to promote my site and shouldn't take to long to get working.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.