Jump to content

Recommended Posts

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 );
}

Link to comment
https://forums.phpfreaks.com/topic/119647-solved-mod-rewrite-with-php/
Share on other sites

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?

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]

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.