How do I rewrite my URL from index.php to sample.php?

by declan_ritchie , in category: SEO , a month ago

How do I rewrite my URL from index.php to sample.php?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by dejuan.watsica , a month ago


There are a few different ways to rewrite your URL from index.php to sample.php, but one of the most common methods is to use mod_rewrite in an Apache web server. Here are the steps to do this:

  1. Create a new file named .htaccess in the root directory of your website if one does not exist already.
  2. Add the following code to the .htaccess file:RewriteEngine On RewriteRule ^index.php$ sample.php [L] This code sets the RewriteEngine to on, which allows you to use mod_rewrite, and then sets up a rule that rewrites any URL that contains index.php to sample.php.
  3. Save the .htaccess file.

Now, when you visit a URL on your website that contains index.php, it will automatically be rewritten to sample.php. For example, if you visit, it will be rewritten to

It's important to note that mod_rewrite requires the Apache web server to be properly configured, and you may need to consult your web hosting provider or server administrator to ensure that it is set up correctly. Additionally, if you have existing rules in your .htaccess file, you may need to modify the code to work with those rules.