Jump to content

fwrite() and Mod Rewrite...


techiefreak05

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


Link to comment
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 _)
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.