2

I'm new in PHP so I faced some problem using URL redirect using .htacess.

My URL page look like this: http://domain.com/blog_detail.php?id=blog_title

But I want change URL using .htaceess like this: http://domain.com/blog/blog_title

I have tried this, but it's not working:

<IfModule mod_rewrite.c>
    RewriteEngine on   # Turn on the rewriting engine
    RewriteRule ^blog/([a-zA-Z0-9_-]+)$ blog_detail.php?id=$1
</IfModule>

2 Answers 2

1

I would use:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f ## respect real files
RewriteCond %{REQUEST_FILENAME} !-d ## respect real directories
RewriteBase /                       

RewriteRule ^blog/(.*)$ blog_detail.php?id=$1&%{QUERY_STRING} [L]

&%{QUERY_STRING} only if you want to pass other variables here and there like:

http://domain.com/blog/blog_title?lang=fr

for instance

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

Comments

0

Try this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^(.*)$ blog_detail.php?id=$1 [QSA,L]
</IfModule>

2 Comments

this code is not working, but if replaced forward slash to hypen then it's working properly.. RewriteRule blog-(.*)$ blog_detail.php?id=$1 [QSA,L]
It may be if your blog script is in folder and is accesible through domain.com/blog/blog_detail.php . In this case you must type correct path like RewriteBase /blog/. I have changed my answer. May be it will help you.

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.