fri3ndly Posted August 14, 2008 Share Posted August 14, 2008 Hi Guys I have a website that currently displays products mod rewritten in the following way: hxxp://www.mydomain.co.uk/content/page-item/type-fancydress/id-125/item-theitemtitle.html which I want to display like this (without variables in the URL): hxxp://www.mydomain.co.uk/item/fancydress/125/theitemtitle.html Would this be easy enough to change? Below is the htaccess and PHP script I use: HTACCESS: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule /(.*)\.html index.php?rewrite=$1 [L] Options +FollowSymlinks RewriteEngine on rewritecond %{http_host} ^mydomain.co.uk [nc] rewriterule ^(.*)$ http://www.mydomain.co.uk/$1 [r=301,nc] PHP: function mod_rewrite( $request, $array_delim, $pair_delim ) { global $_GET, $HTTP_GET_VARS, $_REQUEST; $value_pairs = explode( $array_delim, $request ); $make_global = array(); foreach( $value_pairs as $pair ) { $pair = explode( $pair_delim, $pair ); $_GET[$pair[0]] = $pair[1]; $_REQUEST[$pair[0]] = $pair[1]; $HTTP_GET_VARS[$pair[0]] = $pair[1]; } } // MOD REWITE //////////////////////////////// #if we have a query_string if( $_GET['rewrite']) { $request = $_GET['rewrite']; mod_rewrite( $request, '/', '-' ); # if you have register_globals enables uncomment the following # extract( $_GET, EXTR_OVERWRITE ); } Quote Link to comment https://forums.phpfreaks.com/topic/119647-solved-mod-rewrite-with-php/ Share on other sites More sharing options...
trq Posted August 14, 2008 Share Posted August 14, 2008 Would this be easy enough to change? Yeah, if you know what your doing. Are you stuck? Quote Link to comment https://forums.phpfreaks.com/topic/119647-solved-mod-rewrite-with-php/#findComment-616406 Share on other sites More sharing options...
fri3ndly Posted August 14, 2008 Author Share Posted August 14, 2008 Kind of. To be honest, I do a lot of PHP at work, however I am knew to mod rewrite and this was a script a developer I know wrote for me Quote Link to comment https://forums.phpfreaks.com/topic/119647-solved-mod-rewrite-with-php/#findComment-616417 Share on other sites More sharing options...
wildteen88 Posted August 14, 2008 Share Posted August 14, 2008 Hi Guys I have a website that currently displays products mod rewritten in the following way: hxxp://www.mydomain.co.uk/content/page-item/type-fancydress/id-125/item-theitemtitle.html which I want to display like this (without variables in the URL): hxxp://www.mydomain.co.uk/item/fancydress/125/theitemtitle.html Would this be easy enough to change? If your url is always going to like page/type/id/item.html then yes, however if your url varies then no. Is you url always going to be in the above format? Quote Link to comment https://forums.phpfreaks.com/topic/119647-solved-mod-rewrite-with-php/#findComment-616424 Share on other sites More sharing options...
fri3ndly Posted August 14, 2008 Author Share Posted August 14, 2008 It will always be in that format, but sometimes shorter... eg. hxxp://www.mydomain.co.uk/item/fancydress.html Quote Link to comment https://forums.phpfreaks.com/topic/119647-solved-mod-rewrite-with-php/#findComment-616426 Share on other sites More sharing options...
wildteen88 Posted August 14, 2008 Share Posted August 14, 2008 You'll have to let mod_rewrite set your $_GET variables, rather than PHP (which means dropping your mod_rewrite function). So your mod_rewrites will become RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # matches: item/fancydress/125/theitemtitle.html RewriteRule /([a-z]+)/([a-z]+)/([0-9]+)/([a-z]+)\.html index.php?page=$1&type=$2&id=$3&item=$4 [NC,L] # matches: item/fancydress/theitemtitle.html RewriteRule /([a-z]+)/([a-z]+)/([a-z]+)\.html index.php?page=$1&type=$2&item=$3 [NC,L] # matches: item/fancydress.html RewriteRule /([a-z]+)/([a-z]+)\.html index.php?page=$1&type=$2 [NC,L] Options +FollowSymlinks RewriteEngine on rewritecond %{http_host} ^mydomain.co.uk [nc] rewriterule ^(.*)$ http://www.mydomain.co.uk/$1 [r=301,nc] Quote Link to comment https://forums.phpfreaks.com/topic/119647-solved-mod-rewrite-with-php/#findComment-616445 Share on other sites More sharing options...
fri3ndly Posted August 14, 2008 Author Share Posted August 14, 2008 Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/119647-solved-mod-rewrite-with-php/#findComment-616466 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.