Reputation: 299
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.
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!
Upvotes: 0
Views: 627
Reputation: 164764
RewriteBase /
does nothing if the .htaccess
file is in the document root. Remove itI don't think you need the forward-slash prefix on your substitution. Also, try this single rule
RewriteRule ^employers/events/(\d{4})/(\d{2})/? employers/events/?e_year=$1&e_month=$2 [L,QSA]
I've tested this locally and it works fine using the following .htaccess
file
RewriteEngine on
RewriteRule ^a/b/(\d{4})/(\d{2})/? /a/b/?y=$1&m=$2 [L,QSA]
Using a stand-alone example, your rewrite rules should result in the following query params being passed to the MODx index.php
file
Array
(
[q] => employers/events/
[e_year] => 2013
[e_month] => 02
)
What MODx does with this, I can't say
Upvotes: 1