我们的网站允许使用漂亮的网址“etest.me/1234”,其中“1234”是客户端 ID。正如您在下面看到的,它重定向到我们进行重定向的route.php 文件。问题是,当客户端使用不带“/1234”的“etest.me”时,他们会得到 apache 的“在此服务器上找不到请求的 URL/go/”。信息。我希望当“/1234”丢失时,该网址能够转到另一个页面。
请注意,我们将域和路径转发到不存在的“/go”目录,因此下面的规则将捕获它。以下内容位于根目录下的 .htaccess 文件中。
RewriteEngine On
#restrict rewriting URLs ONLY to paths that DO NOT exist
RewriteCond %{SCRIPT_FILENAME} !-d
# commented out to speed up looking since we are not processig file names anyway
#RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^go/([a-zA-Z0-9/]+)$ ./route\.php?go=$1
最佳答案
对我来说工作得很好。希望这也对您有用。
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^go/([a-zA-Z0-9]+)$ /route.php?go=$1 //when client id exist
RewriteRule ^([a-zA-Z0-9]+)$ /index.php // when no client id
关于php - 漂亮的 URL 条件重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43132244/