Jump to content

Mod Help with /


lango13

Recommended Posts

I am currently stuck trying to work out a mod rewrite issue that I have been stuck on for a while.

 

What I am trying to do is convert every url within my website so that it looks like this:

 

www.url.com/index/id/1/colour/blue  -->  www.url.com/index.php?id=1?colour=blue

 

www.url.com/otherpage/otherid/2/colour/green/size/small  -->  www.url.com/otherpage.php?otherid=2&colour=green&size=small -->

 

So every page within the website will always have its url broken down and separated by a /.

 

Thanks, J

Link to comment
Share on other sites

I'm by no means a mod_rewrite expert, but I think you can't have logic like you are expecting within mod_rewrite rules. You have to tell it how to breakdown /something/else/elseagain/yup

into the appropriate file. It doesn't have the capacity to guess that if you add another /something it would be the color.

 

Link to comment
Share on other sites

I have been told that the following will work... but it doesnt seem to want to work.

 

Code:

RewriteCond %{REQUEST_URI} ^/?(index|otherpage) [NC]
RewriteRule .? %1.php?d=%{REQUEST_URI} [QSA,L]

 

 

PHP Code:

<?php
   if ( isset( $_GET['d'] ) ) {   
       $parts = explode( '/', $_GET['d'] );
       array_shift( $parts ); // Remove the file entry.    
       for ( $i = 0, $l = count( $parts); $i < $l; $i++ ) {        
            $_GET[ $parts[ $i ] ] = $parts[ ++$i ];
       }
   } 
</php> 

Link to comment
Share on other sites

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.