wright67uk Posted August 11, 2011 Share Posted August 11, 2011 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?!? Quote Link to comment https://forums.phpfreaks.com/topic/244544-rewrite-url-within-a-directory/ Share on other sites More sharing options...
manix Posted August 11, 2011 Share Posted August 11, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244544-rewrite-url-within-a-directory/#findComment-1256127 Share on other sites More sharing options...
wright67uk Posted August 12, 2011 Author Share Posted August 12, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/244544-rewrite-url-within-a-directory/#findComment-1256235 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.