Jump to content

Archived

This topic is now archived and is closed to further replies.

techiefreak05

fwrite() and Mod Rewrite...

Recommended Posts

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/user
should be the same thing as going to:
http://www.domain.com/user.html


Share this post


Link to post
Share on other sites
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_name

it should then serve a page called my_user_name.html

That regualar expression is case insensitive and it allows numbers 0-9 and few special characters (- and _)

Share this post


Link to post
Share on other sites
I know how to had the rewrite rule, but i want to do it automatically, when ia user registers, it edits the .htaccess file

Share this post


Link to post
Share on other sites
i added this:
[code]RewriteRule ^([a-zA-Z0-9-_]+)$ $1.html[/code] to .htaccess.. but I get a
500 Internal Server Error .....

Share this post


Link to post
Share on other sites
Works fine for me, make sure you have this in your htaccess file:
[code]RewriteEngine On
RewriteRule ^([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.log
Your host should allow you to access your servers error log. The error should be the last error in the log.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.