简体   繁体   中英

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

I want to make it so when you access the non-written url, for example this one: website.com/profile.php?name=Alex you would get redirected to a 404 not found page. But if you would access website.com/profile/Alex it would just work normally. How could I do this?

You can use these rules:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM