insidus Posted June 14, 2012 Share Posted June 14, 2012 Im trying to get my head around pretty URLs, but i just can't seem to grasp it. .htaccess Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^pretty/([0-9])$ pretty?id=$1 [L] pretty.php <?php echo $_GET['id']; ?> <h1>hi</h1> if i go to http://.....co.uk/pretty it prints "Hi" and an error cause the GET isn't set, it does the same if i go to .co.uk/pretty/2 How does one use pretty urls within a site? i ready hundreds of sites/tutorials on this, and nothing says how you GET the data from the url .co.uk/pretty.php?id=2 works Quote Link to comment https://forums.phpfreaks.com/topic/264154-stuck-with-pretty-urls/ Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 You didn't define a page name for the RewriteRule. It should be something like pretty.php?id=$1 Then it should work. Quote Link to comment https://forums.phpfreaks.com/topic/264154-stuck-with-pretty-urls/#findComment-1353718 Share on other sites More sharing options...
insidus Posted June 14, 2012 Author Share Posted June 14, 2012 RewriteRule ^pretty/([0-9])$ pretty?id=$1 [L] still didn't work im afraid http://insidus.co.uk/pretty.php?id=2 http://insidus.co.uk/pretty/2 Quote Link to comment https://forums.phpfreaks.com/topic/264154-stuck-with-pretty-urls/#findComment-1353965 Share on other sites More sharing options...
insidus Posted June 15, 2012 Author Share Posted June 15, 2012 http://insidus.co.uk/pretty/?id=2 Works, so it seems to be with the GET statement maybe? Quote Link to comment https://forums.phpfreaks.com/topic/264154-stuck-with-pretty-urls/#findComment-1354008 Share on other sites More sharing options...
scootstah Posted June 15, 2012 Share Posted June 15, 2012 This works for me: .htaccess Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^pretty/([0-9]+)$ pretty.php?id=$1 [L] pretty.php <?php echo $_GET['id']; http://example.com/pretty/54 Gives the output: 54 Quote Link to comment https://forums.phpfreaks.com/topic/264154-stuck-with-pretty-urls/#findComment-1354011 Share on other sites More sharing options...
insidus Posted June 15, 2012 Author Share Posted June 15, 2012 Turns out, i needed to include -MultiViews in the .htaccess file to get that bit working, but now for my production site, if i do RewriteRule ^view_job/([0-9]+)$ ./view_job.php?job_id=$1 [L] It loads the page, with the correct 'job', but it doesnt load the CSS file? surely its not needed to make a rewrite to the css aswell? Quote Link to comment https://forums.phpfreaks.com/topic/264154-stuck-with-pretty-urls/#findComment-1354016 Share on other sites More sharing options...
scootstah Posted June 15, 2012 Share Posted June 15, 2012 You have this bit in there right? RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f This will exclude files and directories that physically exist from being rewritten. Also, make sure you are using absolute paths to the CSS file including the domain name. Quote Link to comment https://forums.phpfreaks.com/topic/264154-stuck-with-pretty-urls/#findComment-1354024 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.