Rewrite requests with variables to a directory to root
3 posts
• Page 1 of 1
- sonofamarzipan
- Posts: 2
- Joined: 15 Feb 2015, 14:47
Rewrite requests with variables to a directory to root
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?
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?
Re: Rewrite requests with variables to a directory to root
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]
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]
- sonofamarzipan
- Posts: 2
- Joined: 15 Feb 2015, 14:47
Re: Rewrite requests with variables to a directory to root
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.
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.
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 25 guests