我需要在Apache中进行简单的url重写(.htacess更好) 目标是获得简化的网址。
http://www.mysite.com/ana/
转到http://www.mysite.com/artiste-bio.php?username=ana
http://www.mysite.com/john/
转到http://www.mysite.com/artiste-bio.php?username=john
等...
所以我的用户有一个简化的网址:http://www.mysite.com/username/
除了某些文件夹,例如:
http://www.mysite.com/images/
http://www.mysite.com/scripts/
http://www.mysite.com/admin/
是否可以使用.htaccess进行操作?
此致
答案 0 :(得分:2)
以下是我过去使用过的URL重写的精彩介绍:
http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
要真正从.htaccess
网址重写中获得最大收益,您可能需要查看正则表达式。
答案 1 :(得分:0)
任何事情都可以通过.htaccess完成:
# Enable Rewriting
RewriteEngine on
# Rewrite user URLs
# Input: user/NAME/
# Output: user.php?id=NAME
RewriteRule ^(\w+)/?$ artiste-bio.php?username=$1
此代码摘自一个关于mod_rewrite mod_rewrite in depth
的非常好的教程答案 2 :(得分:0)
试试这个
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) http://www.mysite.com/artiste-bio.php?username=$1 [L]