Reputation: 1
I've been stuck on this for days now and have tried multiple configurations with my .htaccess file but I am at my end. This is what I have so far.
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ http://mywebsite.com/$1/ [L]
RewriteRule ^(.*)/$ $1.php [L]
RewriteRule ^product/([a-z]+)$ /product.php?product_id=$1 [QSA,L]
It properly Rewrites the url for PHP extensions and also appends a trailing slash to any of my urls. My problem is with the last line. I would like all url requests to the product such as mywebsite.com/product/1234 to be passed to my script like mywebsite.com/product.php?product_id=1234.
When I go to mywebsite.com/product/1234/ I get a "404 Not Found" with the error "The requested URL /base_dir/1234.php was not found on this server."
I am on shared hosting with Go Daddy.
Upvotes: 0
Views: 85
Reputation: 10754
The reason is that when you go to: http://mywebsite.com/product/1234/
, your second last RewriteRule
gets kicked in (note that [L]
specifies that no more rewriting will take place after this redirect):
RewriteRule ^(.*)/$ $1.php [L]
which, should redirect you to: http://mywebsite.com/product/1234.php
I am not too familiar with .htaccess rules, but you should interchange the position of your last and second last lines:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^product/([a-z]+)$ /product.php?product_id=$1 [QSA,L]
RewriteRule ^(.*)$ http://mywebsite.com/$1/ [L]
RewriteRule ^(.*)/$ $1.php [L]
Upvotes: 1