htaccess重写规则而不更改URL

时间:2014-10-22 14:38:34

标签: php apache .htaccess mod-rewrite redirect

我在htaccess文件中有这段代码:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteBase /

#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ http://subdomain.example.com/index.php?id=$1 [L,QSA]

但每次我去http://subdomain.example.com/test/test

之类的东西

应该解决:

http://subdomain.example.com/index.php?id=test/test

它确实如此,但它将我的URL更改为上面的URL并且不保留原始URL

1 个答案:

答案 0 :(得分:1)

从目标网址中删除http://

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?id=$1 [L,QSA]

我还在RewriteRule修正了你的正则表达式。