我已设法从网址中删除扩展程序并使用slug而不是product_code查找它。我现在的问题是如何从网址中删除?名称。例如 http://www.adlantic.ie/product?name=safety-knee-pad
最好只喜欢它: http://www.adlantic.ie/product=safety-knee-pad
我的htaccess atm看起来像:
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]
非常感谢您的帮助。
答案 0 :(得分:1)
添加更多规则:
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]