How do I create my own url parser using Apache?

I heard that it can be done with a web.config

. I want to do it like this, for example my url http://help.BHStudios.org/site

can go to http://BHStudios.org/help.php?section=site

or http://i.BHStudios.org/u3Hiu

can redirect to another url stored in the database with a hash u3Hiu

as the key, or if something goes wrong and the internal structure of the file appears as http://Kyli.BHStudios.org/http/bhstudios/v2/self/index.php

(something which happens to GoDaddy's servers for whatever reason) it will change it to its intended URL http://Kyli.BHStudios.org

before it exposes the user.

Since I've never done this before, could you also explain why you gave the answer you did?

+3


source to share


1 answer


A few Apache mod_rewrite rules in your httpd.conf servers or in your .htaccess file, most of what you want will execute in your htdocs directory, for example

RewriteEngine On
RewriteBase  /

# Default Rule - for non physical objects (not a file or directory): 
# Internally rewrite (user won't see the URL) to /index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]

#If the Browser request contains a .php, instruct the browser to remove it.
RewriteCond %{THE_REQUEST}      \.php      [NC]
RewriteRule ^/?(.*)\.php$       http://%{HTTP_HOST}/$1         [R=301,NC,L]

# Specific rule
RewriteRule ^/?site   /help.php?section=site 

      



Masking real filesystem objects won't be perfect and a little pointless as the user just needs to right-click and view the source on any served page to get the actual URLs.

+3


source







All Articles