I am trying to use mod_rewrite and modify WordPress' URL handling to allow for passing variables to PHP from the URL while maintaining "pretty permalink" functionality. (on WP 3.2.1)
Something like this:
http:/epiclasers.com/hello-world (normal with permalinks set to /%postname%)
http:/epiclasers.com/state/hello-world (WP should display the same hello-world post as above, but also would pass the state string to PHP as a variable)
http:/epiclasers.com/state/city/hello-world (WP should display the hello-world post, but would pass the state and city strings to PHP as variables)
I added the following mod_rewrite directives to my .htaccess file:
RewriteRule ^(\w+)/(\w+)/ /index.php?state=$1&city=$2 [L]
RewriteRule ^(\w+)/ /index.php?state=$1 [L]
which kind of works. The variables are being passed, and PHP can grab them with:
$state = $_GET['state'];
$city = $_GET['city'];
The problem is that WP is getting confused by the variables in the URL and isn't outputting the correct template file. URL's like these:
http://epiclasers.com/arizona/phoenix/
http:/epiclasers.com/arizona/phoenix/hello-world
http://epiclasers.com/arizona/
are bringing up the 404 page not found template.
How do I modify the WP URL handling code to ignore the /state and /city parts of the URL without also breaking URLs like:
http:/epiclasers.com/category/category1
http:/epiclasers.com/tag/tag1
http:/epiclasers.com/category/category2/subcategory
etc.
Thanks,
Devin