1

I'm having trouble using a rewrite rule with an index.php file in a subfolder.

I've successfully rewritten queries in the root using

RewriteEngine on
RewriteCond %{QUERY_STRING} &id=169
RewriteRule ^index\.php$ /index.php/169? [L,R=301]

Now I need to write some if a folder called SMF on the same system, for example "/SMF/index.php?topic=916.0"

I've tried putting a .htaccess file in the sub folder

RewriteEngine on
RewriteCond %{QUERY_STRING} &topic=916.0
RewriteRule ^index\.php$ /index.php/topic916? [L,R=301]

And I've tried putting this in my root .htaccess file

RewriteEngine on
RewriteBase /SMF/
RewriteCond %{QUERY_STRING} &topic=916.0
RewriteRule ^index\.php$ /index.php/topic916? [L,R=301]

I think I've got to be missing something simple. Any thoughts? This is my first post here so hopefully I followed all the guidelines right.

  • You are testing with permanent redirects. This messes with caching in your browser, causing all kinds of strange unreproducable bugs. I recommend changing the redirects to temporary, then clearing the cache of your browser and restarting your browser. Once everything works as expected you can make the redirects permanent again. – Sumurai8 Aug 15 '15 at 13:45
  • Stay away from parmesan cheese, and `RewriteBase`. You would only use that in a subfolders´ but not in the webroots´ htaccess. Why do the incoming query strings contain `&topic=…` and not just `?topic=…` - is there another GET parameter before those? (Also it's indeed better to update the generated URLs, than redirecting them afterwards to pretty URLs. See also [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/q/20563772)) – mario Aug 15 '15 at 13:50
  • Thanks Mario. You got me on the right track when you questioned my use of the "&" in my query. While my previous redirects had aditional GET parameters, this one only had one so I removed it and the redirect works! Also I can't update the generated URLs...or I can...but these redirects are for a site that is being phased out so the redirects are to a new site and pretty URLs. All that will be left here is the .htaccess file – Tim Wilborne Aug 16 '15 at 16:10

2 Answers2

0

In the subdir, you had a redirect to /index.php (emphasis on /). If you want it to be relative to the RewriteBase / current directory, drop the leading "/" and rewrite to index.php...

covener
  • 16,079
  • 2
  • 27
  • 40
0

Mario set me on the right track. When you have a single query you should remove the "&". &topic=917.0 should have been topic=917.0

RewriteEngine on RewriteCond %{QUERY_STRING} topic=917.0 RewriteRule ^index.php$ /index.php/topic916? [L,R=301]