如何使用.htaccess重写此URL

时间:2012-10-16 03:02:50

标签: .htaccess url mod-rewrite rewrite

我希望它能显示网址 /index.php?page=somePage&id=someID&siteAddress=someAddress/someAddress/?page=somePage&id=someID

如何为此使用重写规则?

1 个答案:

答案 0 :(得分:0)

要将 / someAddress 内部重写为 /index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^page=([^&]+)&id=([^&]+)$
RewriteRule ^/?([^/]+)/$ /index.php?page=%1%id=%2&siteAddress=$1 [L]

要将 /index.php 外部重定向到 / someAddress

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?page=([^&]+)&id=([^&]+)&siteAddress=(^[&\ ]+)
RewriteRule ^ /%3/?page=%1&id=%2 [L,R=301]