1

I want to redirect my site to friendly. I have my website pull data from database and adress is /post?id=1 and i want to change it to /post/1 I already wrote the code for rewrite but i cant make sense from google research how to redirect to /post/1.

my code

Options +FollowSymLinks
 RewriteEngine on
 RewriteRule ^post/([^/.]+)/?$ post.php?id=$1 [L]
4
  • 1
    What exactly is your problem? Commented Jan 28, 2016 at 14:47
  • Problem is i want to redirect id=1 to post/1 I already rewrote it i just want to redirect it too. Commented Jan 28, 2016 at 15:05
  • Croises's answer should work. Commented Jan 28, 2016 at 15:08
  • 1
    Yes it's perfect :D i Voted him up :D Commented Jan 28, 2016 at 15:10

2 Answers 2

2

Use:

Options +FollowSymLinks
RewriteEngine on

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+post\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /post/%1? [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^post/([^/.]+)/?$ post.php?id=$1 [L,QSA,NC]
Sign up to request clarification or add additional context in comments.

2 Comments

God bless you. Can i ask you where did you learn what each of this things mean? :D
All on this site ;-) Thank you!
0

This one worked for me

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ post.php?id=$1  [NC]

if you goto url /post/check1/

the htaccess file internally call post?id=check1

1 Comment

I want that in reverse if i call post?id=check1 to get /post/check1/

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.