0

Can someone help me with User friendly URL and get variables.

My file is called test.php and i'm using htaccess to remove the .php part of the url. In theory i want the following url construction in the following format: www.example.com/test/1234

where 1234 is my id= part

Whats the best way and how can i do this?

here's my htaccess so far:

Options -Indexes

RewriteEngine  on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L, QSA]

RewriteRule ^(.*)$ test.php?/$1 [L]

i'm trying to get the get variable by:

$var = $_GET['id'];

echo $var;

any help would be greatly appreciated. In future i will be using this to pass products name and using them as get variables to increase seo and the user experience. If you need any more information or any questions im happy to respond

1 Answer 1

1

Can you see if this works?

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

 RewriteRule ^test/(.+)$ test.php?id=$1 [QSA,L]

^ above works

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, That echos out the following: test/123 However test is the file name i.e test.php
Dinesh - thansk for your help, i've cracked it. RewriteRule ^test/(.+)$ test.php?id=$1 [QSA,L] - this works :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.