Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You
- 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?
- ChatGPT
- Copy
- You can achieve this by using a combination of a .htaccess file and some server-side scripting (such as PHP) on your website.
- Create a .htaccess file in the root directory of your website. Add the following code to the .htaccess file:
- RewriteEngine On
- RewriteRule ^([^/]+)/?$ redirect.php?nickname=$1 [L]
- Create a "redirect.php" file in the root directory of your website. Add the following PHP code to the "redirect.php" file:
- <?php
- $nicknames = array(
- 'nickname1' => 'folder1',
- 'nickname2' => 'folder2',
- // Add more nicknames and folder associations as needed
- );
- $nickname = $_GET['nickname'];
- if (array_key_exists($nickname, $nicknames)) {
- $folder = $nicknames[$nickname];
- header("Location: https://sxoliko.com/$folder");
- exit();
- } else {
- // Handle invalid nicknames here (e.g., display an error message)
- echo "Invalid nickname";
- exit();
- }
- Replace 'nickname1', 'folder1', 'nickname2', and 'folder2' with the actual nickname-folder associations you have in your file.
- 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.
- 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