mod_rewrite how to: convert folders in url to get parameters

0

Issue

I am trying to use mod_rewrite to basically do the same thing as this post ie to convert folders in url into query-parameters, and I like the rewrite rules given there:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME) (myserver) [NC]  #my addition for my sandbox
RewriteRule ^([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)/?$ index.php?one=$1&two=$2&three=$3&four=$4&five=$5

but will that work in the .htaccess file or does it need to go in the http.conf file?

I am testing this out on my sandbox machine which uses http://172.xx.xx.xx/myserver/
for this web apps url. On the actual server of course there is no /myserver/ folder needed.
So on the actual server I could maybe get away with putting a .htaccess file in the root or maybe the mod directive in the http.conf (or can’t I?) but on my sandbox what can I do to get this working?

To reiterate: if I use this url: http://my.ip.add.res/myserver/aaa/bbb/ccc
I want it rewritten to: /myserver/index.php?one=aaa&two=bbb&three=ccc etc
Should I put the command in the .htaccess in the myserver folder or elsewhere?

PS I am using apache 2.2.3 on CentOS.

Solution

I am just putting it in the .htaccess file for now, seems to work as desired and I suspect it’ll be good on the production site too.

PS: I have no RewriteBase defined.

Answered By – lost baby

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More