Jump to content

Mod Rewrite


Twistedweb123

Recommended Posts

I'm new to mod rewriting techniques, so this is a little advanced for me, but very easy for anyone with experience.

 

Basically I am making a website, where i want to give users their own directory upon signup through mod rewrite.

 

 

so rather than:

 

mysite.com/users.php?username=xxx

 

They can visit

 

mysite.com/xxx

 

I havnt written the code yet, but im pretty sure I can manage that. The trouble I am having is as follows.

 

Basically, within their username, I want them to have a profile (similar to facebook) in the style that you can click photos, view a small bio, events they are hosting etc.

 

So I want to turn (example:)

 

mysite.com/bio.php?username=xxx

mysite.com/photos.php?username=xxx

mysite.com/events.php?username=xxx

 

to

 

mysite.com/xxx/bio

mysite.com/xxx/photos

mysite.com/xxx/events

 

 

any help will be greatly appreciated

 

Link to comment
https://forums.phpfreaks.com/topic/229100-mod-rewrite/
Share on other sites

Unfortunatly the above code didnt work, as the server always looked for the users.php file, no matter was was entered.

 

However I hve fixed this myself. I had a little play around, and im not sure how dity this code is, but it works for me :)

 

RewriteEngine on
RewriteRule ^([^/\.]+)/events/?$ events.php?artist=$1 [L]
RewriteRule ^([^/\.]+)/tours/?$ tours.php?artist=$1 [L]
RewriteRule ^([^/\.]+)/photos/?$ photos.php?artist=$1 [L]
RewriteRule ^([^/\.]+)/videos/?$ videos.php?artist=$1 [L]
RewriteRule ^([^/\.]+)/bio/?$ bio.php?artist=$1 [L]
RewriteRule ^([^/\.]+)/fans/?$ fans.php?artist=$1 [L]
RewriteRule ^([^/\.]+)/related/?$ related.php?artist=$1 [L]

RewriteRule ^([^/\.]+)/?$ $1.php [L]

 

 

As you can see, if manually entered the files which the user will have a url for - photos, videos, bio etc.

 

I have then written a rewriterule for all files to be accessible in the server as mysite.com/xxx

Link to comment
https://forums.phpfreaks.com/topic/229100-mod-rewrite/#findComment-1181595
Share on other sites

Archived

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

×
×
  • 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.