.htaccess 使用htaccess进行短链接

.htaccess 使用htaccess进行短链接,.htaccess,.htaccess,我有这样的链接 short.dk/testA57_Hi.89-Qwerty 我想重定向到longdomain.dk/index.php?link=testA57_Hi.89-Qwerty 我编写了以下htaccess规则 重定向匹配^/([A-Za-z0-9]+)$$1 它适用于字母和数字,但如何允许URL允许的所有其他字符,如点、破折号、下划线等。尝试改用mod_rewrite: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f Rewr

我有这样的链接 short.dk/testA57_Hi.89-Qwerty

我想重定向到longdomain.dk/index.php?link=testA57_Hi.89-Qwerty

我编写了以下htaccess规则 重定向匹配^/([A-Za-z0-9]+)$$1


它适用于字母和数字,但如何允许URL允许的所有其他字符,如点、破折号、下划线等。

尝试改用mod_rewrite:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9_\-\.]+)$ /index.php?link=$1 [L,QSA]
注意正则表达式的变化:
([A-Za-z0-9\-\.]+

将匹配所有字母、数字和下划线/破折号/点。 您希望使用mod_rewrite而不是mod_alias(
RedirectMatch
)的原因是您需要条件,以便
/index.php
不会最终匹配您的正则表达式并导致循环