1

I'm in the process of working on an error system for my site (i.e., if MySQL encounters an error, it sends them to an error page). I'm wondering, is it possible to use a "/" instead of "?err=" for a URL?

What I'd like to do is have people sent to the url "/error/404/" but display on page the content at url "/error?err=404". Is there a way to do this with HTAccess, or something of the sort?

My current way is with lots of files and iframes, and it gets really annoying when you have to update one tiny little thing.

Thanks!

space55
  • 65
  • 1
  • 1
  • 8
  • I understand, however, I'm not exactly experienced with HTAccess. I tried the rule `RewriteRule ^/error/$ $1?err=$2 [L,QSA] ` however, it just loops. Any suggestions for the specific rule? – space55 Feb 03 '16 at 23:46

2 Answers2

1

What you are looking for is url rewriting. You can set it up using an .htaccess file, given that your installation of apache has mod_rewrite enabled (if not, check this question).

Here is a nice tutorial on how to do it.

Community
  • 1
  • 1
anpel
  • 931
  • 6
  • 16
0

Have a try with this:

RewriteEngine on
RewriteRule ^error/(\d+)$ error?err=$1 [L,QSA]

This should not end in a redirection loop, since this requires a trailing number in the URI.

Note that I removed your leading slashes from both the pattern and the result. .htaccess style files work on relative paths.

In general you should always prefer to place such rules inside your http servers host configuration instead of using .htaccess style files. Those files are notoriously error prone, hard to debug and the really slow the server down. They are only available as a last option for users who do not have access to the host configuration, for example when using a cheap hosting provider.

arkascha
  • 41,620
  • 7
  • 58
  • 90