A modern and scalable URL shortener application built with PHP and MySQL. This web app lets you shorten long URLs into compact, custom short codes and retrieve the original links seamlessly. Perfect for both personal use and production-scale deployment!
- ✂️ Shorten Long URLs
Convert lengthy URLs into concise, easy-to-share short codes. - 🎨 Custom Short Codes
Personalize your short codes for brand recognition. - 🔗 Seamless Redirection
Automatically redirect users from short codes to original URLs. - 🔍 Duplicate Detection
Checks if a URL has already been shortened.
- 🖥️ PHP (>= 7.0)
- 🗄️ MySQL or MariaDB
- 🌐 Web Server (e.g., Apache)
- 📦 Composer (for dependency management)
git https://github.com/SupratimRK/url_shortener.git
cd url-shortener
- Create the database:
CREATE DATABASE url_shortener;
- Create the table:
USE url_shortener;
CREATE TABLE urls (
id INT AUTO_INCREMENT PRIMARY KEY,
original_url VARCHAR(255) NOT NULL,
short_code VARCHAR(10) NOT NULL UNIQUE
);
- (Optional) Insert sample data:
INSERT INTO urls (original_url, short_code) VALUES
('https://www.example.com', 'exmpl'),
('https://www.anotherexample.com', 'anothr');
- Create a
config.php
file in the root directory:
<?php
// MySQL connection parameters
$servername = "yourhost";
$username = "yourusername";
$password = "yourpassword";
$database = "url_shortener";
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
- Include
config.php
inindex.php
:
<?php
include 'config.php';
// ... rest of the code
?>
- Apache Configuration:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "path_to_your_project_directory"
ServerName url-shortener.local
<Directory "path_to_your_project_directory">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
- Update Hosts File:
127.0.0.1 url-shortener.local
- Restart Apache:
sudo service apache2 restart
🌐 Open your browser and visit: http://url-shortener.local
-
Shorten a URL:
- Enter your URL in the input field.
- (Optional) Add a custom short code.
- Hit the "Shorten" button.
-
Retrieve the Original URL:
- Access the short code in your browser (e.g.,
http://url-shortener.local?x=shortcode
). - The app redirects to the original URL if the code exists.
- Access the short code in your browser (e.g.,
Here is a screenshot of the URL shortener in action:
🔓 This project is licensed under the MIT License. Check the LICENSE file for details.
We welcome contributions! Whether it's bug fixes, feature enhancements, or new ideas, feel free to:
- 🛠️ Submit a Pull Request
- 🐛 Open an Issue
Let’s make this project even better together!
For inquiries, feedback, or support, reach out to [email protected].
💡 Demo the Application Now:
Visit and explore the app live: xrl.rf.gd
⭐ Don’t forget to give a star on GitHub if you like it!
Let me know your thoughts, and feel free to fork the repo for your custom needs! 😊