获取htaccess重写规则只重写特定的URL

时间:2013-10-20 14:17:22

标签: apache .htaccess mod-rewrite url-rewriting

我只想重写这个特定的网址:

http://www.website.co.uk/php/project.php?project=anythingHerehttp://www.website.co.uk/php/project/anythingHere

这很好但是当我去http://www.website.co.uk/php/project/anythingHere时 它也改变了所有链接(样式表,javascript,超链接......我不想改变的事情)。例如:

http://www.website.co.uk/php/index.phphttp://www.website.co.uk/php/project/index.php


这就是我已经

RewriteEngine On
RewriteCond %{HTTP_HOST} ^website.com\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.website.com\.co\.uk$
RewriteRule ^clients$ "http\:\/\/website.com\.co\.uk\/billing\/index\.php" [R=301]
RewriteRule ^project/([^/]*)$ /php/project.php?project=$1

1 个答案:

答案 0 :(得分:0)

你可以尝试这段代码:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?website\.co\.uk$ [NC]
RewriteRule ^clients/?$ http://website.co.uk/billing/index.php [NC,L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(php/project)\.php\?project=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(php/project)/([^/]+)/?$ /$1.php?project=$2 [L,QSA,NC]