PHP:如何将非英语URL重写为index.php


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

我在.htaccess中使用此代码重写所有页面以索引.php页面:

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

它与英文网址完美配合。但是,它在访问非英语 URL 时显示 404 错误。

例如:mywebsite.com/%EA%B3%A0%EC%B9%B4%EC%A7%80%EB%85%B8 或 mywebsite.com/고카지노

那么,如何重写它们呢?谢谢!

不要限制你的规则。像这样使用它:

# 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]