mod_rewrite module allows to manipulate url using unlimited number of rules . Each rule consist of unlimited number of condition
-
Problems
You want to redirect user if they try to access some page
You want to Deny visitors by IP address or by referrer
You want to force scripts to display as source code
You want to Ensure media files are downloaded instead of played
You want to Prevent requests with invalid characters
Syntax
#The Rule:
RewriteEngine on
RewriteCond Testingstring condition [optionalFlags]
RewriteRule Pattern Substitution [OptionalFlags]
Example
RewriteEngine on
RewriteRule ^oranges.html$ apples.html
RewriteCond %{REMOTE_ADDR} ^(12\.34\.56\.789)$
RewriteRule (.*) - [F,L]
Working
-
1
-
3
-
5-6
Server Variable
HTTP Headers
Variable | Description |
---|---|
%{HTTP_USER_AGENT} | Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with get_browser() to tailor your page's output to the capabilities of the user agent. |
%{HTTP_REFERER} | The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted. |
%{HTTP_COOKIE} | It contains the raw value of the 'Cookie' header sent by the user agent. |
%{HTTP_HOST} | Contents of the Host: header from the current request, if there is one. |
%{HTTP_ACCEPT} | Contents of the Accept: header from the current request, if there is one. |
Server Internals
Variable | Description |
---|---|
%{DOCUMENT_ROOT} | The document root directory under which the current script is executing, as defined in the server's configuration file. |
%{SERVER_ADMIN} | The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host. |
%{SERVER_NAME} | The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host. |
%{SERVER_ADDR} | The IP address of the server under which the current script is executing. |
%{SERVER_PORT} | The port on the server machine being used by the web server for communication. For default setups, this will be '80'; using SSL, for instance, will change this to whatever your defined secure HTTP port is. |
%{SERVER_PROTOCOL} | Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0'; |
%{SERVER_SOFTWARE} | Server identification string, given in the headers when responding to requests. |
Request
Variable | Description |
---|---|
%{REMOTE_ADDR} | The IP address from which the user is viewing the current page. |
%{REMOTE_HOST} | The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user. |
%{REMOTE_PORT} | The port being used on the user's machine to communicate with the web server. |
%{REMOTE_USER} | The authenticated user. |
%{REQUEST_METHOD} | Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'. |
%{SCRIPT_FILENAME} | The absolute pathname of the currently executing script. |
%{PATH_INFO} | Contains any client-provided pathname information trailing the actual script filename but preceding the query string, if available. For instance, if the current script was accessed via the URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, then $_SERVER['PATH_INFO'] would contain /some/stuff. |
%{QUERY_STRING} | The query string, if any, via which the page was accessed. |
%{AUTH_TYPE} | When doing HTTP authentication this variable is set to the authentication type. |
Regular Expression
Syntax
Start_Anchor([Character_Representor]|Character){Size_Of_Character}...........End_Anchor
Example
^[a-zA-Z0-9.+-_]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$
Working
The above expression represent the valid pattern of e-mail address . Broken down that is:
- It is start anchor . It denote the start of string
- This is charecter representor. [ ] only allow specified charecter inside it
- This denote the size of [a-zA-Z0-9.+-]. It means there must be one or more character
- This is the real character. Real character should not have its size
- This is charecter representor. [ ] only allow specified charecter inside it
- This denote the size of [a-zA-Z0-9.-]. It means there must be one or more character
- This represent real character '.'. Forward slash is used to omit it's special meaning as '.' represent any character
- This is charecter representor. [ ] only allow specified charecter inside it
- This denote the size of [a-zA-Z]. It means there must be two character and it can be upto 63 character
- It is end anchor . It denote the end of string
No comments:
Post a Comment