techiefreak05 Posted August 18, 2006 Share Posted August 18, 2006 I was wondering if its possible to write a Rewrite Rule to the .htaccess file with fwrite. like when a user registers to my site, i want it to add a rewrite rule that is: [code]^user$ user.html[/code]ex.: http://www.domain.com/usershould be the same thing as going to: http://www.domain.com/user.html Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 18, 2006 Author Share Posted August 18, 2006 *bump* lol ;D Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 18, 2006 Share Posted August 18, 2006 I guess user gets replaced with the actuall username of some user. And you are adding in new rules for each user for your site. I would not recommend this but a better way is to use a regular expressesion instead. So add this to your .htaccess file:[code]^([a-zA-Z0-9-_]+)$ $1.html[/code]That will now do it automatically. So if you went to your site and did this:mysite.com/my_user_nameit should then serve a page called my_user_name.htmlThat regualar expression is case insensitive and it allows numbers 0-9 and few special characters (- and _) Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 18, 2006 Author Share Posted August 18, 2006 I know how to had the rewrite rule, but i want to do it automatically, when ia user registers, it edits the .htaccess file Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 18, 2006 Author Share Posted August 18, 2006 i added this:[code]RewriteRule ^([a-zA-Z0-9-_]+)$ $1.html[/code] to .htaccess.. but I get a 500 Internal Server Error ..... Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 18, 2006 Share Posted August 18, 2006 Works fine for me, make sure you have this in your htaccess file:[code]RewriteEngine OnRewriteRule ^([a-zA-Z0-9-_]+)$ $1.html[/code]and Apache has the mod_rewrite module enabled.You should be able to find out why its failing by looking in Apaches error log file, called error.logYour host should allow you to access your servers error log. The error should be the last error in the log. Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 21, 2006 Author Share Posted August 21, 2006 Yes RewriteRule is on, Im using it for other pages.... but this thing doesnt work.. heres the error i got:[code]/home/zyco/public_html/.htaccess: RewriteRule: cannot compile regular expression '^([a-zA-Z0-9-_]+)$'\n[/code] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 22, 2006 Share Posted August 22, 2006 What version of Apache have you got? I'm not sure why its not working. I'm new too to mod_rewrite however I use this on my one of my scripts I'm creating.Try it as just, do you get anything with that?[code]RewriteRule ^([a-zA-Z0-9]+)$ $1.html[/code]Also as this is more to do with mod_rewrite I'll move this to the Apache forum. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.