Jump to content


Photo

fwrite() and Mod Rewrite...


  • Please log in to reply
7 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 18 August 2006 - 07:15 AM

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:
^user$ user.html

ex.: http://www.domain.com/user
should be the same thing as going to:
http://www.domain.com/user.html



Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 18 August 2006 - 08:34 AM

*bump* lol  ;D
Link shortener with advanced, detailed statistics:

http://tyny.us/

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 18 August 2006 - 09:23 AM

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:
^([a-zA-Z0-9-_]+)$ $1.html
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 _)

#4 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 18 August 2006 - 10:15 AM

I know how to had the rewrite rule, but i want to do it automatically, when ia user registers, it edits the .htaccess file
Link shortener with advanced, detailed statistics:

http://tyny.us/

#5 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 18 August 2006 - 10:19 AM

i added this:
RewriteRule ^([a-zA-Z0-9-_]+)$ $1.html
to .htaccess.. but I get a
500 Internal Server Error .....
Link shortener with advanced, detailed statistics:

http://tyny.us/

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 18 August 2006 - 01:56 PM

Works fine for me, make sure you have this in your htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-_]+)$ $1.html
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.

#7 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 21 August 2006 - 09:41 PM

Yes RewriteRule is on, Im using it for other pages.... but this thing doesnt work..
heres the error i got:

/home/zyco/public_html/.htaccess: RewriteRule: cannot compile regular expression '^([a-zA-Z0-9-_]+)$'\n

Link shortener with advanced, detailed statistics:

http://tyny.us/

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 22 August 2006 - 11:21 AM

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?
RewriteRule ^([a-zA-Z0-9]+)$ $1.html

Also as this is more to do with mod_rewrite I'll move this to the Apache forum.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users