Advertisement
plirof2

redirect to subfolder sxoliko.com/nick2

Jun 23rd, 2024 (edited)
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. You
  2. I have a website in sxoliko.com with some subfolders. I have a file that associates a nickname with each folder. How can I redirect to the correct folder if I enter a path like sxoliko.com/nickname2?
  3.  
  4.  
  5. ChatGPT
  6. Copy
  7. You can achieve this by using a combination of a .htaccess file and some server-side scripting (such as PHP) on your website.
  8.  
  9. Create a .htaccess file in the root directory of your website. Add the following code to the .htaccess file:
  10.  
  11. RewriteEngine On
  12. RewriteRule ^([^/]+)/?$ redirect.php?nickname=$1 [L]
  13. Create a "redirect.php" file in the root directory of your website. Add the following PHP code to the "redirect.php" file:
  14.  
  15. <?php
  16. $nicknames = array(
  17.     'nickname1' => 'folder1',
  18.     'nickname2' => 'folder2',
  19.     // Add more nicknames and folder associations as needed
  20. );
  21.  
  22. $nickname = $_GET['nickname'];
  23.  
  24. if (array_key_exists($nickname, $nicknames)) {
  25.     $folder = $nicknames[$nickname];
  26.     header("Location: https://sxoliko.com/$folder");
  27.     exit();
  28. } else {
  29.     // Handle invalid nicknames here (e.g., display an error message)
  30.     echo "Invalid nickname";
  31.     exit();
  32. }
  33. Replace 'nickname1', 'folder1', 'nickname2', and 'folder2' with the actual nickname-folder associations you have in your file.
  34.  
  35. Now, when a visitor enters a path like "sxoliko.com/nickname2" in their browser, the .htaccess file will redirect the request to the "redirect.php" file with the nickname as a GET parameter. The PHP script will then retrieve the associated folder from the file and redirect the visitor to the correct folder.
  36. Make sure to test this setup thoroughly to ensure it works as expected. Additionally, consider adding error handling and security measures to protect your website from potential exploits.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement