Mod rewrite mod rewrite howto
我使用下面的mod rewrite代码来编写URL,比如:Mod rewrite mod rewrite howto,mod-rewrite,Mod Rewrite,我使用下面的mod rewrite代码来编写URL,比如:www.site.com/play/543 RewriteEngine On RewriteRule ^play/([^/]*)$ /index.php?play=$1 [L] 如何在此基础上进行扩展,以便我可以拥有两个URL,如www.site.com/contact和www.site.com/about RewriteRule ^(play|contact|about)/([^/]*)$ /index.php?$1=$2 [L]
www.site.com/play/543
RewriteEngine On
RewriteRule ^play/([^/]*)$ /index.php?play=$1 [L]
如何在此基础上进行扩展,以便我可以拥有两个URL,如www.site.com/contact
和www.site.com/about
RewriteRule ^(play|contact|about)/([^/]*)$ /index.php?$1=$2 [L]
也许能奏效。现在对/play/foo的请求指向/index.php?play=foo,/contact/bar指向/index.php?contact=bar,依此类推
编辑,从注释“关于和联系人”将永远不会被设置 那就用两次重写吧
RewriteRule ^play/([^/]*)$ /index.php?play=$1 [L]
RewriteRule ^(contact|about)/?$ /index.php?a_variable_for_your_page=$1 [L]
也许能奏效。现在对/play/foo的请求指向/index.php?play=foo,/contact/bar指向/index.php?contact=bar,依此类推
编辑,从注释“关于和联系人”将永远不会被设置 那就用两次重写吧
RewriteRule ^play/([^/]*)$ /index.php?play=$1 [L]
RewriteRule ^(contact|about)/?$ /index.php?a_variable_for_your_page=$1 [L]
大多数PHP框架使用的常用方法是将用户请求的任何内容(现有文件除外)(通常是assets*.png、*.js*.css)和/或公共目录)传递到PHP脚本,然后在PHP端解释路由
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d #if not an existing directory
RewriteCond %{REQUEST_FILENAME} !-f #if not an existing file
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] #pass query string to index.php as $_GET['url']
</IfModule>
因此,在接受用户输入和清理/过滤时要非常小心,以避免远程用户访问web主机上的非公共文件。大多数PHP框架使用的常用方法是只传递用户请求的任何内容,现有文件除外(通常是assets*.png、*.js*.css)和/或公共目录,然后在PHP端解释路由
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d #if not an existing directory
RewriteCond %{REQUEST_FILENAME} !-f #if not an existing file
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] #pass query string to index.php as $_GET['url']
</IfModule>
因此,在进行用户输入和清理/筛选时要非常小心,以避免远程用户访问您的web主机上的非公共文件。但是将永远不会设置about和contact。但是将永远不会设置about和contact。