Reputation: 21
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>
Upvotes: 2
Views: 1154
Reputation: 424
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^(.*)$ blog_detail.php?id=$1 [QSA,L]
</IfModule>
Upvotes: 0
Reputation: 1190
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
Upvotes: 1