如果第一个变量是“profile”,则用两个变量重写规则

时间:2013-05-24 22:56:42

标签: .htaccess mod-rewrite

请原谅我的英文,

我目前正在重写[example.com/about - > example.com?page=about]

如果请求的页面是" profile",我想重写第二个变量,因此制作[example.com/profile/johndoe - > example.com?page=profile&name=johndoe]

换句话说;需要第二个变量的唯一情况是请求的页面是Profile。这可以作为重写规则吗?

提前多多感谢,

我目前使用它:

RewriteEngine On

# WWW-Rewrite

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


# Remove trailing slash(es)

    RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1 


# Rewrite /sth  ->  ?page=sth

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^([^/]*)/?$ /?page=$1 [L]

1 个答案:

答案 0 :(得分:0)

只需更改你的htaccess,除了www-rewrite和尾随斜杠

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/(.*)$ page=profile&name=$1[L]
RewriteRule ^(.*)$ page=$1 [L]
相关问题