Skip to content
Advertisement

PHP make subfile of a placeholder file?

I have the following structure for my site:

./u/
./u/profile.php
./u/comics.php

profile.php is filtered with the viewer’s username. For example, the account Venk would be ./u/Venk. I need comics.php to somehow be a subfolder of this but I’m not sure how to go about doing so. It should end up looking like this: ./u/Venk/comics.

How can I get this to work?

P.s, I could just use AJAX to do this ./u/comics?username=Venk but that is just ugly and inconsistent and just overall makes my site’s theme look messy so I’d much prefer an alternative.

P.p.s, Feel free the edit the post to make the title more concise, I wasn’t really sure how to word it in basic terminology.

Advertisement

Answer

Create a .htaccess file in root with this content, make sure mod_rewrite is enabled.

You don’t have to keep PHP files inside u directory, move profile.php and comics.php to root as well.

RewriteEngine On

# from: /u/{word}/comics
# to: /comics?username={word}
RewriteRule ^u/(w+)/comics$ /comics.php?username=$1
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement