.htaccess-rewrite找不到我想要的内容


.htaccess rewrite cant find what i want

我想用.htaccess重写一些url,因为我不喜欢domain.com/link.php/string=1234,它太长了。

所以我想用.htaccess把它重写成domain.com/1234。但是1234字符串只是一个占位符。因此,它也可以是4321,然后必须重写为domain.com/4321。我知道.htaccess可以做到这一点,但我不是这方面的专家,我在谷歌上也没有找到一个好的、具体的教程。

我被困了,什么也找不到,所以我希望有人能帮我。

尝试将此代码放在web根目录(通常为/var/www)的.htaccess文件中:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
# rewrite the URL and pass it to link.php
RewriteRule ^(.*)$ /link.php/string=$1 [L,QSA]

这将重写所有URL以包括"/link.php/string=".

您可以在root.htaccess文件中使用此规则:

RewriteEngine on
RewriteRule ^([0-9]+)/?$ /link.php/string=$1 [L,QSA]

但是我在搜索一些东西,所以domain.com/1234会重定向到domain.com/link.php/?字符串=1234某人