Page 1 of 1

Open Write in Location in a .htaccess file

Posted: Wed Oct 25, 2006 6:17 pm
by tecktalkcm0391
How/ what do I need to make php open up .htaccess and then add in some text right before the #end username urls in:
# Start Username URLs
Redirect /chris /viewprofile.php?user=chris
# End Username URLs

And say I want it to find the line that has chris in it and delete it or replace it how would I do that ?

I've looked at fopen and fclose, I know how to do those but I cant find how to do this.

Posted: Wed Oct 25, 2006 6:59 pm
by feyd
file_get_contents() + strpos(), possibly substr_replace() + fopen() + fwrite() + fclose().

However, it would seem that you could engineer your rewrite such that it didn't need to be modified when you wanted to add someone.

There have been a few rewrite related posts that involved detecting if the request points to an existing file, directory, or symbolic link. Failing those tests, you can then direct it to pass that request to some handling script. This script could look for a context where that request makes sense, for instance searching the username list or performing a site-wide search or some other behavior.

Posted: Wed Oct 25, 2006 7:02 pm
by Cameri
Well, first make sure you have the right access to the file, CHMOD sounds like it?

Imho, you shouldn't be able to access/edit .htaccess file from php, because, if anyone could edit any .htaccess located on the web server root, then they will be able to gain access anywhere.

Posted: Wed Oct 25, 2006 7:42 pm
by Zoxive
Couldn't you just use something like..
RewriteRule ^([0-9a-z_]+)/?$ /viewprofile.php?user=$1 [NC,L]
-NSF