重写我的网址,删除查询字符串并创建新的漂亮网址 [英] rewrite my url, remove query string and make new pretty url
问题描述
我想从 http://website.com/preview.php?id重写我的网址= puzzled 到 http://website.com/cv/puzzled 并从 http://website.com/resume.php?id=puzzled 到 http://website.com/puzzled ...但是似乎我无法获得此结果.
I want to rewrite my url from http://website.com/preview.php?id=puzzled to http://website.com/cv/puzzled and from http://website.com/resume.php?id=puzzled to http://website.com/puzzled ... but seems i am failed to get this result.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z-]+) /resume.php?id=$1 [QSA,L]
RewriteRule ^cv/([0-9a-zA-Z-]+) /preview.php?id=$1 [QSA,L]
推荐答案
尝试一下,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^cv/([\w-]+)$ preview.php?id=$1
RewriteRule ^([\w-]+)$ resume.php?id=$1
RewriteRule ^([\w-]+).php$ $1 [L]
从Apache mod_rewrite文档
From Apache mod_rewrite docs
变量SCRIPT_FILENAME和REQUEST_FILENAME包含相同的变量 value-内部request_rec的文件名字段的值 Apache HTTP Server的结构.名字是通常的 已知的CGI变量名称,而第二个是适当的 REQUEST_URI的对应内容(包含uri字段的值 的request_rec).
The variables SCRIPT_FILENAME and REQUEST_FILENAME contain the same value - the value of the filename field of the internal request_rec structure of the Apache HTTP Server. The first name is the commonly known CGI variable name while the second is the appropriate counterpart of REQUEST_URI (which contains the value of the uri field of request_rec).
如果发生替换并且重写继续,则值 这两个变量都会相应地更新.
If a substitution occurred and the rewriting continues, the value of both variables will be updated accordingly.
如果在每个服务器的上下文中使用(即,在将请求映射到之前 文件系统)SCRIPT_FILENAME和REQUEST_FILENAME不能包含 完整的本地文件系统路径,因为该路径在此阶段未知 处理.这两个变量最初将包含的值 在这种情况下为REQUEST_URI.为了获得完整的本地文件系统 每个服务器上下文中请求的路径,请使用基于URL的预读 %{LA-U:REQUEST_FILENAME}以确定的最终值 REQUEST_FILENAME.
If used in per-server context (i.e., before the request is mapped to the filesystem) SCRIPT_FILENAME and REQUEST_FILENAME cannot contain the full local filesystem path since the path is unknown at this stage of processing. Both variables will initially contain the value of REQUEST_URI in that case. In order to obtain the full local filesystem path of the request in per-server context, use an URL-based look-ahead %{LA-U:REQUEST_FILENAME} to determine the final value of REQUEST_FILENAME.
这篇关于重写我的网址,删除查询字符串并创建新的漂亮网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!