Skip to content

Instantly share code, notes, and snippets.

@subrotoice
Last active November 11, 2023 04:27
Show Gist options
  • Save subrotoice/1870b220f257338437bdb3c168758b6a to your computer and use it in GitHub Desktop.
Save subrotoice/1870b220f257338437bdb3c168758b6a to your computer and use it in GitHub Desktop.
NB: Any Rule start with "RewriteRule ^" + Type url in browser + PHP file need to load
# .htaccess to get the value from url ie. edeves.com/myValue
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?id=$1
# index.php
<?php
if(isset($_GET["id"])){
if($_GET["id"]!="") {
echo "User ID: " . $_GET["id"]; // User ID: myValue
var_dump($_GET);
} else {
echo "index.php";
var_dump($_GET);
}
} else {
echo "None";
}
# Url will be same but script load from a.php; edeves.com/myValue
RewriteEngine On
RewriteRule ^$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9]+)$ a.php?id=$1 // script load from here not index.php
# Redirect
RewriteRule ^tracking/([a-zA-Z0-9]+)$ tracking_link_en.php?code=$1 [QSA,L] // edeves.com/tracking/23424 --> tracking_link_en.php?23424
RewriteRule ^subtest/$ subtest/index.php?code=$1 [QSA,L] // edeves.com/subtest --> index.php
RewriteRule ^subtest/([a-zA-Z0-9]+)$ subtest/index.php?code=$1 [QSA,L] // https://prnt.sc/mpJGGOsaf-Qz
https://www.brontobytes.com/knowledgebase/149/.htaccess-RewriteRule-Examples.html?language=english&currency=7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment