2010-11-30 5 views
2

J'ai cette URL et je dois saisir les balises et réécrire l'URLComment regex et .htaccess réécrire url

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

Ainsi, dans l'exemple ci-dessus pour faire quelque chose comme http://beantownbride.com/?s=Social+Media

Voici ce que j'ai jusqu'à présent pour mon fichier .htaccess

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

mais il ne fonctionne que pour la première balise (si i t fonctionne à tous)

l'ensemble du fichier .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

Qu'entendez-vous par _ "le premier tag" _? Y a-t-il plus d'un paramètre 'tag'? – jwueller

+1

Non, comme si j'ai plusieurs tags comme Social + Media – Alex

Répondre

0

Je pense que vous manquez la balise de fin de $ pour votre expression régulière. Essayez la ligne suivante à la place:

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

également, consultez cet article pour les règles et options supplémentaires:

http://www.workingwith.me.uk/articles/scripting/mod_rewrite

+0

J'ai essayé mais cela n'a pas fonctionné ... – Alex

+0

Je reçois une erreur de 500 – Alex

+0

pourriez-vous envoyer votre fichier .htaccess entier? – dabito

1

Je sais que c'est une vieille question, mais j'ai une réponse pour ceux qui cherchent encore pour une réponse.

Vous devez faire correspondre la chaîne de requête dans une condition antérieure à la règle.

IE:

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

Le %2 dans la règle est la seconde référence de retour à l'état.