I’m trying to mod_rewrite a URL folder structure to a query string internally but retain the original URL…
ie. http://www.mysite.com/employers/events/2013/02
becomes:
http://www.mysite.com/employers/events/?e_year=2013&e_month=02
…internally. From the browser I’d like to see the original folder-based URL. My efforts have the URL being rewritten properly but the browser shows the query string URL instead. My code is as follows:
RewriteEngine On
RewriteRule ^employers/events/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ /employers/events/?e_year=$1&e_month=$2 [L]
RewriteRule ^employers/events/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/$ /employers/events/?e_year=$1&e_month=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
The second rule is just to catch the version with a trailing slash.
Many thanks in advance, this is causing me great pain.
Update:
This is what’s being passed:
Array ( [q] => employers/events/ [e_year] => 2013 [e_month] => 02 )
So MODx is clearly sabotaging things internally.. not the best news but a bit of closure at least!
RewriteBase /does nothing if the.htaccessfile is in the document root. Remove itI don’t think you need the forward-slash prefix on your substitution. Also, try this single rule
I’ve tested this locally and it works fine using the following
.htaccessfileUpdate
Using a stand-alone example, your rewrite rules should result in the following query params being passed to the MODx
index.phpfileWhat MODx does with this, I can’t say