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
https://forums.phpfreaks.com/topic/101631-mod-help-with/
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
https://forums.phpfreaks.com/topic/101631-mod-help-with/#findComment-520013
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
https://forums.phpfreaks.com/topic/101631-mod-help-with/#findComment-520093
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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