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 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. 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 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? 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 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? 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. Link to comment https://forums.phpfreaks.com/topic/264154-stuck-with-pretty-urls/#findComment-1354024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.