Alex France
Alex France

Reputation: 45

Htaccess issues - Redirecting from pretty url to php version

I am not a new developer and have worked with .htaccess for years, but today I'm totally stuck and have no idea what is going on. Below is my full htaccess file:

Options All -Indexes

ReWriteEngine On

RewriteRule ^page/([a-zA-Z0-9_-]+)$ page.php?pageurl=$1
RewriteRule ^([a-zA-Z0-9_-]+)$ category.php?categoryurl=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)-([a-zA-Z0-9_-]+)$ product.php?category=$1&subcategory=$2&productid=$3&producturl=$4


RewriteCond %{HTTP_HOST} www.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]

website.com/category should take me to the category page which it does, but for some reason the url gets changed, as if htaccess is working in reverse, I get sent to website.com/category.php?categoryurl=category.

This is exactly the same for the other ones, my product page should be website.com/category/subcategory/123-producturl but it redirects too:

website.com/product.php/category/123-producturl?category=category&subcategory=subcategory&productid=123&producturl=producturl

Anybody have any idea at all why this is doing what it is?

Upvotes: 0

Views: 92

Answers (1)

Ahmed Habib
Ahmed Habib

Reputation: 189

Try this one, you have not added flags to end the line in HTACCESS.

Options All -Indexes

ReWriteEngine On

RewriteRule ^page/([a-zA-Z0-9_-]+)$ page.php?pageurl=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)$ category.php?categoryurl=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)-([a-zA-Z0-9_-]+)$ product.php?category=$1&subcategory=$2&productid=$3&producturl=$4 [L]


RewriteCond %{HTTP_HOST} www.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]

Upvotes: 0

Related Questions