Jump to content

Stuck with pretty URLs


insidus

Recommended Posts

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

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

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?

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.