user3215045
user3215045

Reputation: 75

creating clean urls using .htaccess

Helllo i have this page that has a dynamic table that consist of records of a recordset, i have displayed this records successfully, but on click on any item on my dynamic table it gives me an ugly url

localhost/sms/mem.php?id=8"

but i want to convert this url to something like this

localhost/sms/mem/8

i have read and tried to create clean urls, but it dosent seem to convert my url to a clean url automatically, this is wht i have tried using

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ mem.php?id=$1
RewriteRule ^([a-zA-Z0-9]+)/$ mem.php?id=$1

am i doin something wrong, cause the way its been explained online it seems pretty simple

Upvotes: 1

Views: 118

Answers (1)

anubhava
anubhava

Reputation: 785128

Place this before your existing rule:

RewriteEngine On
RewriteBase /sms/

RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]

RewriteCond %{THE_REQUEST} \s/+sms/mem\.php\?id=([^\s&]+) [NC]
RewriteRule ^ mem/%1? [R=301,L]

RewriteRule ^mem/([a-zA-Z0-9]+)/?$ mem.php?id=$1 [L,QSA,NC]

This should be places in /sms/.htaccess file

Upvotes: 1

Related Questions