简体   繁体   中英

PHP: How to rewrite non-English URL to index.php?

I use this code in .htaccess to rewrite all page to index.php page:

RewriteRule ^([][\w\s$:!()'"-]+)/?$ ?file=$1 [L]

It worked perfectly with English URL. However, it show 404 Error when access non-English URL.

For example: mywebsite.com/%EA%B3%A0%EC%B9%B4%EC%A7%80%EB%85%B8 or mywebsite.com/고카지노

So, how to rewrite them ? Thank you very much !

Don't restrict your rule. Use it like this:

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ ?file=$1 [L,QSA]

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