URL重写(Mod_Rewrite)

时间:2013-11-07 02:38:11

标签: mod-rewrite url-rewriting

嗨,我对mod_rewrite一无所知。 我问我如何根据需要重写这个URL。

website.com?page=pagename&content=contents&action=download

as

website.com/pagename/contents/download

不会始终设置参数“action”。不确定这是否有所作为。

1 个答案:

答案 0 :(得分:0)

尝试将此添加到文档根目录中的htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /?page=$1&content=$2&action=$3 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /?page=$1&content=$2 [L,QSA]