现在我有.htaccess文件为我的profile.php(根目录)重写url
RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
此代码将http://127.0.0.1/projects/webproject/profile.php?username=sarah
转换为http://127.0.0.1/projects/webproject/sarah
情况:
说,我有“update_availability.php”(根目录),并使用此格式http://127.0.0.1/projects/webproject/update_availability.php?month=03&day=18&year=2014
访问它。
我想将网址更改为http://127.0.0.1/projects/webproject/update_availability.php/03/18/2014
。
我想知道的事情:
http://127.0.0.1/projects/webproject/update_availability.php?month=03&day=18&year=2014
转换为 http://127.0.0.1/projects/webproject/update_availability.php/03/18/2014
。我是.htaccess的新手。我将不胜感激任何帮助。
答案 0 :(得分:1)
您可以使用:
RewriteEngine On
RewriteBase /webproject/
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^([\w-]+)$ profile.php?username=$1 [L,QSA]
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(update_availability(?:\.php)?)/([0-9]+)/([0-9]+)/([0-9]+)/?$ $1?month=$2&day=$3&year=$4 [L,QSA,NC]