mod_rewrite help

atlanis

New Member
Messages
24
Reaction score
0
Points
0
I'm not sure if this is the right forum or not, but here goes.

I have the following setup:
Main Domain: http://atlanis.pcriot.com/
Subdomain: http://evil.atlanis.pcriot.com/
Subdomain root: /public_html/evil/

/public_html/evil/.htaccess:
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^/user/(.+)/?$ /sig.php?user=$1 [L]
I'm trying to turn http://evil.atlanis.pcriot.com/user/maryjane into http://evil.atlanis.pcriot.com/sig.php?user=maryjane. I have verified that the substitution URL is working, but the rewritten version (/user/maryjane) is giving me a 404 error. What can I do to fix it? I read on the forums that free hosts have mod_rewrite, so it should work if my .htaccess is done right (which is apparently isn't).
 

AngusThermopyle

Active Member
Messages
319
Reaction score
52
Points
28
Code:
RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/user/.*$
RewriteRule ^user/(.*)$ sig.php?user=$1 [L]

will work
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
The rest of the story: the essential difference is the lack of a leading slash in the pattern. What's happening is that the rewrite engine has to handle per-directory rewrites (those set in .htaccess) differently than global rewrites (those in the conf files): it has to strip the directory prefix before processing, including a trailing slash. For example, the URL path "/user/fred" is translated to the file path "/home/atlanis/public_html/user/fred". For rewrite rules in "/home/atlanis/public_html/.htaccess", the "/home/atlanis/public_html/" is stripped from the file path, so the patterns are matched against "user/fred". If you want a pattern that works in any context, start it with "^/?" (e.g. "^/?user/(.+)/?".

Read the mod_rewrite documentation for more, particularly the technical details and RewriteBase directive.
 
Top