Jump to content

rewrite url within a directory


wright67uk

Recommended Posts

Hello im trying to tidy up my URLS and wondered if anybody could give me some advice.

 

I have loads of links which have been dynamically generated by my php code;

my site is www.i-stevenage.co.uk

 

Here is a snippet of code from one of the sections in my site;

 

<?php
$query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Cars and Travel' AND confirmed ='Yes' ORDER BY name");
echo mysql_error();
while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0];
$i = -1;
foreach($nt as $value)
{$i++;
$FileName = str_replace(' ','_',$nt[$i]) . ".php";
$FileUsed = str_replace('_',' ',$nt[$i]);
echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?subtype=$FileUsed'>"  . ucwords(strtolower (($nt[$i]))) . "</a>" . "<br/>";
$FileHandle = fopen($FileName, 'w') or die("cant open file");
$pageContents = file_get_contents("header.php");
fwrite($FileHandle,"$pageContents");}
fclose($FileHandle);
?>

 

This generates the following links;

 

http://www.i-stevenage.co.uk/VALETING.php?subtype=VALETING

http://www.i-stevenage.co.uk/CAR_WINDSCREENS.php?subtype=CAR WINDSCREENS

http://www.i-stevenage.co.uk/COURIER.php?subtype=COURIER

http://www.i-stevenage.co.uk/CAR_REPAIRS.php?subtype=CAR REPAIRS

http://www.i-stevenage.co.uk/CURTAINS.php?subtype=CURTAINS

http://www.i-stevenage.co.uk/SALES.php?subtype=SALES

 

Is it possible to have a rewrite that says do not display .php?and anything after .php?      ?

 

so that my links look like;

 

http://www.i-stevenage.co.uk/VALETING

http://www.i-stevenage.co.uk/CAR_WINDSCREENS

 

Im fairly new to .htaccess and wasnt sure if im going to have to write a new rule for every url in my site (about 80 i think) or wether I can write a generic rule that can apply to all of the URL's.

 

Hope this makes sense?!?

Link to comment
Share on other sites

I seriously doubt my knowledge on htaccess outruns yours a lot but I am pretty sure this would work

 

RewriteEngine On

 

RewriteCond %{REQUTEST_FILENAME} !-d

RewriteCond %{REQUTEST_FILENAME} !-f

RewriteCond %{REQUTEST_FILENAME} !-l

 

RewriteRule ^VALETING$ VALETING.php?subtype=VALETING [L,NS]

RewriteRule ^CAR_WINDSCREENS$ CAR_WINDSCREENS.php?subtype=CAR WINDSCREENS [L,NS]

 

 

and so on for the rest, hit me back if it worked

Link to comment
Share on other sites

Hey thankyou for the reply,

 

It did however come up as a server error.

I also tried the below;

 

<Files ~ "^\.(htaccess|htpasswd)$">

allow from all

</Files>

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(i-stevenage\.co\.uk)(:80)? [NC]

RewriteRule ^(.*) http://www.i-stevenage.co.uk/$1 [R=301,L]

RewriteRule ^http://www.i-stevenage.co.uk/VALETING$ http://www.i-stevenage.co.uk/VALETING.php?subtype=VALETING [L]

#I added the above line to my existing .htaccess

order deny,allow

 

 

this access file didnt give me an error, but nor did it have any effect.

So back to the drawing board i think!

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.