.htaccess 将丑陋的URL转换为用户友好的URL

.htaccess 将丑陋的URL转换为用户友好的URL,.htaccess,.htaccess,在我的网站上有很多丑陋的URL,现在我需要将它们重写为友好的用户友好URL 以下是我的网站中一些丑陋的URL: http://www.mydomain.com/profiles/tutors/index.php?code=1285&name=Ricky+Pointing http://www.mydomain.com/profiles/centers/index.php?code=2285&name=City+&+Gills http://www.mydomain.com

在我的网站上有很多丑陋的URL,现在我需要将它们重写为友好的用户友好URL

以下是我的网站中一些丑陋的URL:

http://www.mydomain.com/profiles/tutors/index.php?code=1285&name=Ricky+Pointing
http://www.mydomain.com/profiles/centers/index.php?code=2285&name=City+&+Gills
http://www.mydomain.com/about.php
http://www.mydomain.com/contact.php.... and much more
因此,我正在寻找一个很好的用户友好的解决方案来解决上述丑陋的URL,如下所示:

http://www.mydomain.com/tutors/Ricky_Pointing.html
http://www.mydomain.com/centers/City_&_Gills.html
http://www.mydomain.com/about.html
http://www.mydomain.com/contact.html
我在.htaccess文件中尝试了类似的方法

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profiles/tutors/index.php\?code=([0-9]+)&name=([^&]+)&?([^\ ]+)
RewriteRule ^profiles/tutors/index\.php /%1/%2/?%3 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.+)/$ /profiles/tutors/index.php?code=$1&name=$2 [L,QSA]
但还是没有运气。 有人能帮我做这个吗?
谢谢。

我想你可能用
RewriteCond
s之类的东西把它复杂化了。您可能会有如下规则:

RewriteRule ^about\.html$ about.php [L]
RewriteRule ^contact\.html$ contact.php [L]
RewriteRule ^tutors/(.*)\.html$ /profiles/tutors/index.php?name=%1 [L]
RewriteRule ^centers/(.*)\.html$ /profiles/centers/index.php?name=%1 [L]

然后,您必须修改PHP脚本以查找具有该名称的适当内容,而不必依赖于
code
的存在。它还必须处理原始URL中存在的下划线。

您始终可以使用URL缩短器。你可以从我的网站上找到更多的信息,我知道,我不是有意把它转换成类似的东西。我的意思是。您是对的,可以通过向数据库中添加另一列并存储缩短的url来完成。它不需要实际的url缩短器。