2010-11-30 29 views
2

我有這個網址,我需要搶標籤和重寫URL如何正則表達式和重寫的.htaccess URL

http://beantownbride.com/darkroom/mt/mt-search.cgi?blog_id=1&tag=Social%20Media&limit=20&IncludeBlogs=1

所以,在上面的例子中,以更多的東西像這樣http://beantownbride.com/?s=Social+Media

這裏是我到目前爲止我的.htaccess文件

RewriteRule ^http://beantownbride.com/darkroom/mt/mt-search.cgi?blog_id=(*.)&tag=(*.) http://beantownbride.com/?s=$2 

,但它僅適用於第一個標籤 (如果我ŧ在所有工作)

整個.htaccess文件

RewriteEngine On 
# BEGIN WordPress 



#MT to WP 
# Convert old archives 
RewriteRule ^/archives/([0-9]*)\.php$ /$1/ [R=301,L] 
RewriteRule ^/archives/([0-9]*)\.html$ /$1/ [R=301,L] 
RewriteRule ^/archives/([0-9]*)\.shtml$ /$1/ [R=301,L] 
RewriteRule ^/archives/([0-9][0-9][0-9][0-9]/[0-9][0-9]/.*)\.php$ /$1/ [R=301,L] 
RewriteRule ^/archives/old/([0-9]*)\.php$ /$1/ [R=301,L] 
RewriteRule ^/archives/cat_(.+)\.php$ /category/$1/ [R=301,L] 
RewriteRule ^/archives/cat_(.+)\.html$ /category/$1/ [R=301,L] 
RewriteRule ^/archives/cat_(.+)\.shtml$ /category/$1/ [R=301,L] 
RewriteRule ^/archives/?$ /archive/ [R=301,L] 
RewriteCond %{REQUEST_URI} !^/archives/[0-9][0-9][0-9][0-9]/[0-9][0-9]/?.*$ [NC] 
RewriteCond %{REQUEST_URI} !^/archives/[0-9][0-9][0-9][0-9][0-9][0-9]\.?.*$ [NC] 
RewriteCond %{REQUEST_URI} !^/archives/tag/.*$ [NC] 
RewriteCond %{REQUEST_URI} !^/archives/author/.*$ [NC] 
RewriteRule ^/archives/(.*)$ /category/$1 [R=301,L] 
RewriteRule ^/archives/(.*)$ /$1 [R=301,L] 

# Change underscores hyphens 
RewriteRule ^/category/([^_]*)_([^_]*)_([^_]*)_(.*)$ /category/$1-$2-$3-$4/ [R=301,L] 
RewriteRule ^/category/([^_]*)_([^_]*)_(.*)$ /category/$1-$2-$3/ [R=301,L] 
RewriteRule ^/category/([^_]*)_(.*)$ /category/$1-$2/ [R=301,L] 
RewriteRule ^/([0-9][0-9][0-9][0-9]/[0-9][0-9])/([^_/]*)_([^_/]*)_([^_/]*)_(.*)/(.+)$ /$1/$2-$3-$4-$5/$6 [R=301,L] 
RewriteRule ^/([0-9][0-9][0-9][0-9]/[0-9][0-9])/([^_/]*)_([^_/]*)_(.*)/(.+)$ /$1/$2-$3-$4/$5 [R=301,L] 
RewriteRule ^/([0-9][0-9][0-9][0-9]/[0-9][0-9])/([^_/]*)_(.*)/(.+)$ /$1/$2-$3/$4 [R=301,L] 

# Change to wordpress feeds 
RewriteRule ^/atom$ /wp-atom.php [R=301,L] 
RewriteRule ^/atom\.xml$ /wp-atom.php [R=301,L] 
RewriteRule ^/index\.atom$ /wp-atom.php [R=301,L] 
RewriteRule ^/index\.rdf$ /wp-rdf.php [R=301,L] 
RewriteRule ^/index\.xml$ /wp-rss2.php [R=301,L] 
RewriteRule ^/rss\.xml$ /wp-rss.php [R=301,L] 
Redirect permanent /rss.xml /feed/ 

RewriteRule ^/([0-9][0-9][0-9][0-9]/[0-9][0-9]/.*)\.atom$ /$1/feed/ [R=301,L] 
RewriteRule ^/([0-9][0-9][0-9][0-9]/[0-9][0-9]/.*)\.atom/$ /$1/feed/ [R=301,L] 
RewriteRule ^/([0-9][0-9][0-9][0-9]/[0-9][0-9]/.*)\.xml$ /$1/feed/ [R=301,L] 
RewriteRule ^/([0-9][0-9][0-9][0-9]/[0-9][0-9]/.*)\.xml/$ /$1/feed/ [R=301,L] 

Redirect permanent /about.html /about 
Redirect permanent /advertise.html /advertise 
Redirect permanent /contact.html /contact 
Redirect permanent /welcome-about/ /about/ 
Redirect permanent /welcome-about/welcome-to-my-blog.html /about/ 
Redirect permanent /real-wedding /real-weddings 

RewriteRule ^/events/(.*)$ /?s=events 

#http://beantownbride.com/darkroom/mt/mt-search.cgi?blog_id=1&tag=Social%20Media&limit=20&IncludeBlogs=1 
#RewriteRule ^/darkroom/mt/mt-search.cgi?blog_id=1&tag=(*.)&limit 
#http://beantownbride.com/?s=test+tag+blah 

#RewriteRule ^http://beantownbride.com/darkroom/mt/mt-search.cgi?blog_id=(.*)&tag=(.*)$ http://beantownbride.com/?s=$2 
RewriteRule ^http://beantownbride.com/darkroom/mt/mt-search.cgi?blog_id=(.*)&tag=(.*)$ http://beantownbride.com/?s=$2 

<IfModule mod_rewrite.c> 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 
+0

你是什麼意思由_「第一個標記」_?是否有多個`tag`參數? – jwueller 2010-11-30 20:26:12

+1

不,如果我有多個標籤,如社交媒體 – Alex 2010-11-30 20:33:39

回答

1

我知道這是一個老問題,但我對這些答案仍在尋找尋求答案。

您需要在規則之前的條件中匹配查詢字符串。

IE:

RewriteCond %{QUERY_STRING} ^blog_id=(.*)&tag=(.*)$ 
RewriteRule ^http://beantownbride.com/darkroom/mt/mt-search.cgi$ http://beantownbride.com/?s=%2 

在規則的%2是在條件第二後參考。