我如何重定向用户,如果使用非重写的url从Htaccess


How can I redirect users if using the non-rewritten url from Htaccess?

我想让它,所以当你访问非书面的url,例如这一个:website.com/profile.php?name=Alex你会被重定向到一个404未找到的页面。但是如果你访问website.com/profile/Alex,它就会正常工作。我怎么能这么做?

您可以使用以下规则:

Options -MultiViews
RewriteEngine On
# 404 if using internal URL directly
RewriteCond %{THE_REQUEST} /profile'.php'?name= [NC]
RewriteRule ^ - [R=404,L]
# rewrite for /profile/alex
RewriteRule ^(profile)/(['w-]+)/?$ $1.php?name=$2 [L,QSA,NC]