2

I have a WordPress plug-in and theme that are malforming a URL call to an external css file. I will fix that later, but until then, I need to do a redirect so the css is getting served correctly.

REQUEST_URI contains the full path, so why doesn't this work?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/?wp-content/plugins/jetpack/css/%22https:/fonts.googleapis.com/css?family=Open+Sans%22$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/?wp-content/plugins/jetpack/css/"https:/fonts.googleapis.com/css?family=Open+Sans"$
RewriteRule ^(.*)$ https://fonts.googleapis.com/css?family=Open+Sans [R,L]
</IfModule>

Note 1: I have tried several combinations of escaping characters in the RewriteCond. Nothing works. Note 2: I am using flag [R,L] for testing, to prevent browser caching. Will change to [R=301,L] later. Note 3: I have tested to verify that the problem is with the RewriteCond, not the RewriteRule.

UPDATE:

OK, so this was a bad question and a dumb mistake. Even though raw REQUEST_URI contains the query string, mod_rewrite specifically does not allow query string to be in REQUEST_URI for matching purposes. Hence, QUERY_STRING instead. I thought that it could be done either way.

I don't have a true query string in my REQUEST_URI -- I have the query string that is in a string that I wanted to match -- so that is why I didn't go to QUERY_STRING at the outset. But mod_rewrite still sees the ? as a typical query string start.

Sorry, guys. I can handle it like this until I fix the underlying problem in WordPress:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/?wp-content/plugins/jetpack/css/%22https:/fonts.googleapis.com/css(.*)$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/?wp-content/plugins/jetpack/css/"https:/fonts.googleapis.com/css(.*)$
RewriteRule ^(.*)$ https://fonts.googleapis.com/css?family=Open+Sans [R,L]
</IfModule>

With WordPress, always remember to put your rewrites above the WordPress rewrites.

zzzaaabbb
  • 139
  • 1
  • 10

0 Answers0