John
John

Reputation: 171

Simple .htaccess rewrite rule but doesn't work properly

I've trying to rewrite one url but something doesn't work as must and I get the massage

Not Found The requested URL /1/1.html was not found on this server.

This is what I have in .htaccess

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^/([^/]*)/([^/]*)\.html$ /view.php?id=$1&name=$2 [L]

And this is the href link for this case

href="/'.$row['id'].'/'.$row['name'].'.html"

Any idea why is this?

Upvotes: 1

Views: 24

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19026

You must remove leading slash in your rule

RewriteRule ^([^/]+)/([^/]+)\.html$ /view.php?id=$1&name=$2 [L]

You need a leading slash in your rules only if you write it directly in httpd.conf instead of .htaccess files.

You also need it until Apache 2.4 if i don't make a mistake

Upvotes: 2

Related Questions