MsKazza
MsKazza

Reputation: 97

How can i remove the filename and the ? from the url

I have managed to remove the extension from the url and got it looking up using a slug not product_code. My question now is how do i remove the ?name from the url. e.g. http://www.adlantic.ie/product?name=safety-knee-pad

Preferably would love to have it just: http://www.adlantic.ie/product=safety-knee-pad

my htaccess atm looks like:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

Thanks very much for any help.

Upvotes: 2

Views: 35

Answers (1)

anubhava
anubhava

Reputation: 784878

Add more rules:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /product(?:\.php)?\?name=([^\s&]+) [NC]
RewriteRule ^ product=%1? [R=302,L,NE]

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

# internal forward from pretty URL to actual one
RewriteRule ^product=(.+)$ product?name=$1 [L,QSA,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

Upvotes: 1

Related Questions