2013-05-20 98 views
0

在我的网站中有很多丑陋的网址,现在我需要将它们重写为用户友好的网址。将丑陋的网址转换为用户友好的网址

这些都是从我的网站丑陋的网址:

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] 

但仍然没有运气。 任何人都可以帮助我做到这一点? 谢谢。

+0

你总是可以使用网址缩写。你可以找到更多的信息从http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener – AliBZ

+0

我知道,我不是故意将它转换为像http:// www。 mydomain.com/dgGc32G。我的意思是像http://www.mydomain.com/Ricky_Pointing。你是对的,它可以通过向数据库添加另一列并存储缩短的URL来完成。它不需要一个真正的网址缩写。 – AliBZ

回答

0

我认为你可能会用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中存在的下划线。