RewriteRule ^(.*)/?$ ./view.php?id=$1
This works if say an id = “abc123”, I can access www.site.com/abc123 perfectly fine.
But I want to be able to access with www.site.com/view/abc123
So I tried:
RewriteRule ^view/(.*)/?$ ./view.php?id=$1
But to no avail. When I try to access www.site.com/view/abc123 it seems as if it doesn’t even grab the $_GET request to get the id.
What’s wrong?
My entire .htaccess:
RewriteEngine On
RewriteBase /~user/sitetest/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^view/(.+?)/?$ view.php?id=$1
Edit:
Using the above .htaccess, when I access:
http://localhost/~user/sitetest/view/abc123
It doesn’t load the $_GET[] from view.php. I even tried echoing out $_GET[] but it shows up as blank.
If I edit it to be RewriteRule ^(.+?)/?$ view.php?id=$1
And access http://localhost/~user/sitetest/abc123 it works fine.
If I edit it to be RewriteRule ^view-(.+?)/?$ view.php?id=$1
And access http://localhost/~user/sitetest/view-abc123 it works fine.
Does it have something to do with the slash??
Try something like this:
Using RewriteBase, you are specifically telling the server to use view.php in the server’s root. If you don’t specify the RewriteBase, the server will use the view.php in the requested directory (being /view/).
Hope this helps 🙂