Nayeem Hyder Riddhi
Nayeem Hyder Riddhi

Reputation: 611

Why URL parameter is not working rewrite URL htaccess?

I am trying to get blog details page with rewriting URL

like this ->> www.sitename.com/blog/test-post

My code is

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/?([a-z]+) details.php [L]
</IfModule>

My problem is , it is coming the details page, but the blog list page

www.sitename.com/blog/

also redirecting to blog details page. how can i avoid this. i also tried with number code like this

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^/?([0-9]+) details.php [L]
</IfModule>

the url with number parameter works fine, but letters is not working. how to solve this?

Upvotes: 1

Views: 31

Answers (1)

anubhava
anubhava

Reputation: 785631

You need to skip files and directories from your rule:

<IfModule mod_rewrite.c>
RewriteEngine on

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . details.php [L]

</IfModule>

Upvotes: 1

Related Questions