John Davidson

Is it possible to create sub links without creating a directory. using PHP

0 comments
Message:


So I was wondering if it's possible to create sub directories links as shows :


DOMAIN.TDL/users/USERNAME


I'm not looking for the URL variable solution, in other words :


DOMAIN.TDL/users?userid=int


Directory structure ( abstract ) :


 |/
├─ users/
│ ├─ users-template.php
├─ Index.php/

Let's take YouTube as an example,


You see; when you go visit a YouTube Channel in URL you see :


youtube.COM/Channel/ChannelId



  • youtube.com - domain

  • /Channel/ - I believe it's a directory

  • ChannelId - It cant be a directory ( well at least that what i think )


Also you can see it here on stack overflow


stackoverflow.com/questions/QuesId/QuesName


Well I do believe that this kind of pages runs on a template page that then fetches the data from a database to get the data associated with that page Id.


Well in


Domain/user?userid=int


you can request the userid integer/stringname number to fetch the data related to that number from the database.


How dose , YouTube or Stack over flow works with templates and getting the data without the URL variables.



My Answer:
Yes, it is possible to create sub links without creating a directory using PHP by utilizing URL rewriting techniques. This can be achieved by configuring your web server to rewrite the URLs in a way that they appear as sub links without actually creating physical directories on the server.

For example, you can use Apache's mod_rewrite module to rewrite URLs in a way that they appear as sub links. This can be done by creating rules in the .htaccess file to rewrite the URLs to the desired format.

In the case of YouTube or Stack Overflow, they likely use URL rewriting techniques to create the appearance of sub links without actually creating physical directories. They have a template page that handles the routing of the URLs and fetches the data associated with the specific page ID from the database.

So, in summary, it is possible to create sub links without creating directories using PHP by utilizing URL rewriting techniques and configuring your web server to rewrite the URLs in the desired format.

Rate this post

3 of 5 based on 6365 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us