0

I've been working on a 301 redirect for a dynamic URL for the past couple days and have really been struggling.

I am looking to redirect example.com/?feed=podcast to example.com/feed/podcast

Here is my current .htaccess file:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^feed$ "http\:\/\/example\.com\/feed\/podcast" [R=301,L]

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

# END WordPress

I am trying to add a redirect for a dynamic URL. I have been able to get this to work:

RewriteCond %{QUERY_STRING} ^pizza$
RewriteRule ^$ http://www.example.com/feed/podcast? [R=301,L]

But I can't get this to work:

RewriteCond %{QUERY_STRING} ^feed=podcast$
RewriteRule ^$ http://www.example.com/feed/podcast? [R=301,L]

It ends up redirecting back to example.com

Any help would be much appreciated!

HeatfanJohn
  • 366
  • 5
  • 14
JonRojas
  • 11
  • 2

1 Answers1

0

This is working for me:

Options All -Indexes

ErrorDocument 403 /Forbidden

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteCond %{QUERY_STRING} ^feed=podcast$
RewriteRule ^$ http://www.example.com/feed/podcast? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

At first I thought that you had to escape the equal sign ("=") with a backslash (which did work, but as displayed above also does the redirect.

C:\Apache24\htdocs>curl -s --verbose http://localhost/?feed=podcast -o null
* Hostname was NOT found in DNS cache
*   Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET /?feed=podcast HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Thu, 27 Aug 2015 21:43:43 GMT
* Server Apache/2.4.10 (Win64) PHP/5.6.4 is not blacklisted
< Server: Apache/2.4.10 (Win64) PHP/5.6.4
< Location: http://www.example.com/feed/podcast
< Content-Length: 243
< Content-Type: text/html; charset=iso-8859-1
<
{ [data not shown]
* Connection #0 to host localhost left intact
HeatfanJohn
  • 366
  • 5
  • 14