2014-01-08 80 views
1

從查詢字符串中刪除第一個變量我用下面的代碼重寫我的這個網址:通過htaccess的

http://example.com/foldername/New-York-Mills.php?ff_nm_from=new+york&search=hotel&location=north+park

來代替查詢字符串「/」所以它的http://example.com/foldername/sa/new+york/hotel/north+park

我已經實現了以下htaccess代碼。

RewriteCond %{THE_REQUEST} \ /+foldername/New-York-Mills\.php\?ff_nm_from=([^&]+)&search=([^&\ ]+)&location=([^&\ ]+) 
RewriteRule^/foldername/sa/%1/%2/%3? [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^foldername/sa/([^/]+)/([^/]+)/([^/]+)$ /Just-dial/New-York-Mills.php?ff_nm_from=$1&search=$2&location=$3 [L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /style.css [NC] 
RedirectMatch 301 ^/(.*)\%2[Cc](.*)$ /$1$2? 

RewriteRule ^foldername/sa/(.+)/(.+)/(.+)/(.+)/? foldername/sa/$1.php?ff_nm_from=$2&search=$3&location=$4 

但我想我的網址如下面的url。這意味着我想在查詢字符串後從url中刪除第一個變量。 http://example.com/foldername/New-York-Mills/hotel/north+park

如何使用.htaccess文件來完成?

+0

只是爲了澄清,你想重寫'http://example.com/foldername/New -York-Mills.php?ff_nm_from = new + york&search = hotel&location = north park'到'http:// example.com/foldername/New-York-Mills/hotel/north + park'? – Jon

回答

0

如果我理解正確的話,你可以取代你第一套的重寫條件和規則是:

RewriteCond %{THE_REQUEST} ^/foldername/New-York-Mills\.php 
RewriteCond %{QUERY_STRING} ff_nm_from=([^&]+)&search=([^&\ ]+)&location=([^&\ ]+) 
RewriteRule^/foldername/New-York-Mills/%2/%3? [L,R=301]