Rewrite requests with variables to a directory to root

Helicon Ape provides support for Apache .htacces and .htpasswd configuration files for Microsoft IIS.
User avatar
Posts: 2
Joined: 15 Feb 2015, 14:47

Rewrite requests with variables to a directory to root

15 Feb 2015, 14:54

Hi, I've been struggling with this for may hours after reading and trying to grasp the bascis of rewrite.

In short, a user has an id for example sonofamarzipan and the url without rewriting would read

http://www.website.com/mydir/index.asp?id=sonofmarzipan

It should rewrite to:

http://www.website.com/sonofamarzipan and http://www.website.com/sonofamarzipan/

The closest I have come to getting it to work is with:

RewriteRule ([^/]+)/$ /mydir/index.asp\?id=$1 [NC,L]

RewriteRule ^([^/]+)$ /mydir/index.asp\?id=$1 [NC,L]

But this also rewrites every directory on the domain instead of only the /mydir/ directory.

So I think this is something with

RewriteCond %{REQUEST_URI} ^/mydir

But I don't know how to get this working with the correct RewriteRule to get the http://www.website.com/sonofamarzipan and http://www.website.com/sonofamarzipan/ result.

Can anyone help me with this? I think I am close...or at least near the right track?

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite requests with variables to a directory to root

16 Feb 2015, 06:31

Hello,

You are right, you are close.
Please try the following rules:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /mydir/index.asp\?id=$1 [NC,L]

User avatar
Posts: 2
Joined: 15 Feb 2015, 14:47

Re: Rewrite requests with variables to a directory to root

16 Feb 2015, 07:05

Thank you so much Anton. This was great!

I'd been trying to use this (http://htaccess.madewithlove.be/) but I think the syntax might be slightly different for htaccess so it was incredibly hard to try to test and make the break through.

But now I learn a little more. Thanks again for this. Really appreciate your time and effort in replying.

Return to Helicon Ape

Who is online

Users browsing this forum: No registered users and 25 guests