We help IT Professionals succeed at work.
Get Started

Redirect and Rewrite URL using .htaccess

Last Modified: 2016-09-21

I want to redirect and then rewrite my URL (internal forwarding) so that it doesn't show the php extension as well it doesn't show the ?, = and & in the URL.

This is the example of what I want to achieve, my actual URL passed to header is http://localhost/portal/error.php?error=runtime-error which I want to show in the address bar http://localhost/portal/error.php/error/runtime-error and internally this URL is forwarded to the actual URL http://localhost/portal/error.php?error=runtime-error.

Also, what I want to achieve is here is single redirect and single rewrite rule(for internal forwarding) which applies to all the scripts instead of adding individual redirect and rewrite rules for each script page.

Below is the code that is present in my .htaccess file.
ErrorDocument 404 /portal/error.php
ErrorDocument 500 /portal/error.php

RewriteEngine On
RewriteBase /
RewriteRule ^include/(.*)$ /portal/error.php [L,R=404]

Open in new window

Kindly let me know if any more information is required.

Thanks in advance
Watch Question
Web Developer, specialising in WordPress
Most Valuable Expert 2011
This problem has been solved!
Unlock 2 Answers and 38 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE