RewriteEngine On
RewriteRule ^([^.]+)$ index.php?name=$1
我想使用像if子句这样的重写规则。 只有在斜杠后面的URL中有一个部分并且没有属性时才应该重定向。
website.com/article -> website.com/index.php?name=article
website.com/theme/artcile -> no redirection
website.com/article?any=attribute -> no redirection
答案 0 :(得分:1)
可以使用此规则来完成:
RewriteEngine On
# make sure there is no query parameter
RewriteCond %{QUERY_STRING} ^$
# make sure there is nothing after a slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ index.php?name=$1 [L]
这将重写:
website.com/article -> website.com/index.php?name=article
website.com/article/ -> website.com/index.php?name=article
这不会影响任何这些网址:
website.com/theme/artcile
website.com/article?any=attribute