Jump to content

Recommended Posts

Hello,

 

I am thinking of changing the structure of my CMS for future websites to produce more search engine friendly urls.

 

Currently the urls I get are;

www.mydomain.com/index.php?page=wooden-windows

 

What I want to acheive is;

www.mydomain.com/windows/wooden-windows/

 

I know this can be done with mod rewrite but I was thinking this may be possible to do from the get go with php? Here is what I think would be possible;

 

Create links within the cms structure by pulling out the current pages parent e.g.

 

www.mydomain.com/parent1/parent2/actual-page/

 

then when the page is requested a line of code at the top of the page uses explode to find the last / and retrieves the page as "actual-page". the next bit of code then queries the database and drags out all the info for the record with unique reference "actual-page".

 

Does this sound like it would work properly and does any see any problems that might occur with it?

 

Thanks

 

Dan

No I wasn't intending on doing but now you've pointed that out I suppose that would be the only way, back to the drawing board :'(

 

In your opinion is mod rewrite the only option for achieving Search Engine (SE) friendly urls?

I was looking at mod re-write as a cure to the problem as oppose to a fix so was thinking starting from scratch maybe it could be done from php. I think maybe I was over complicating the situation though.

 

Thanks for putting me back on the right track, I think this is the mod re-write I would need to use to get my desired urls?

 

Options +FollowSymlinks

RewriteEngine on

RewriteRule ^([^/]+)/([^/]+)/([^/]+).php /index.php?page=$3&parent1=$1&parent2=$2 [NC]

 

Maybe after some further research I could complete this with some if statements for if parent1 or parent2 is not set

I was looking at mod re-write as a cure to the problem as oppose to a fix so was thinking starting from scratch maybe it could be done from php. I think maybe I was over complicating the situation though.

 

Thanks for putting me back on the right track, I think this is the mod re-write I would need to use to get my desired urls?

 

Options +FollowSymlinks

RewriteEngine on

RewriteRule ^([^/]+)/([^/]+)/([^/]+).php /index.php?page=$3&parent1=$1&parent2=$2 [NC]

 

Maybe after some further research I could complete this with some if statements for if parent1 or parent2 is not set

 

Problem with this is if you want to add a new parent, you have to update the match. What if your 20 nested deep?

 

The desired way is to route everything to a front controller (with exception of some resources like images etc), and then your frontcontroller will parse the url. That way you can keep all your logic and variable management in php.

 

Try to download Zend or Wordpress to see how they manage this. Simple htaccess file has:

 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

 

Then you use parse_url() in your app to manage the variables (i.e. 'parent1' above).

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.