Vinod Sebastian – B.Tech, M.Com, PGCBM, PGCPM, PGDBIO

Hi I'm a Web Architect by Profession and an Artist by nature. I love empowering People, aligning to Processes and delivering Projects.

Tag: URL Rewrite

URL Rewrite

  • HTTP Status Messages

    Understanding HTTP Status Messages

    HTTP status messages are an essential part of web communication, indicating the outcome of a client’s request to a server. These messages are categorized into different groups based on their meaning and purpose.

    2xx – Success

    HTTP status codes starting with 2 indicate success. When a client receives a 2xx status code, it means that the request was successfully received, understood, and accepted by the server.

    3xx – Redirection

    Redirection status codes (3xx) inform the client that further action needs to be taken to complete the request. These codes are used when a resource has been moved to a new location temporarily or permanently.

    • 301 – Moved Permanently: This status code informs the client that the requested resource has been permanently moved to a new location. It is advised to update any bookmarks or links to the old URL.
    • 303 – Redirect: Indicates that the client should use a different HTTP method to perform the request. The new URI should not be used for subsequent requests.
    • 307 – Moved Temporarily: Similar to 301 but indicates that the resource has been temporarily moved. For subsequent requests, the client should continue to use the original URI.

    4xx – Client Error

    Status codes in the 4xx range indicate client errors. These codes are returned when there is an issue with the client’s request, such as unauthorized access, missing parameters, or malformed requests.

    5xx – Server Error

    When a server encounters an error while processing a client’s request, it returns a status code in the 5xx range. These errors are typically related to server misconfigurations, overloads, or unhandled exceptions.

    Understanding HTTP status messages is crucial for developers and system administrators to troubleshoot and resolve issues related to web communication effectively.

  • General

    URL Rewrite in Web Development

    URL rewriting is a technique used in web development to modify the URL structure that the server receives. Unlike redirection, which sends a new URL back to the browser for another request, URL rewriting reconstructs the URL for the script on the server side.

    Redirection can be categorized into two common types: 301 redirection, which is permanent, and 302 redirection, which is temporary. The type of redirection used can impact how search engines update their databases.

    Benefits of URL Rewriting

    • URL rewriting enables the separation of the URL from the actual resource, making it easier to locate resources on a website.
    • For instance, a user-friendly URL like www.abc.com/aboutus can be internally rewritten to www.abc.com/page.php=1, improving user experience and SEO.

    URL Rewriting Modules

    Various web servers utilize specific modules for URL rewriting:

    • Apache: Apache web server employs the mod_rewrite module for URL rewriting.
    • Windows IIS: Windows IIS server uses the ISAPI Rewrite module, often requiring a paid license for advanced features.

    Sample URL Rewrite Configuration

    
    RewriteEngine On
    RewriteBase /base
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} !^id=0$
    RewriteRule ^products/(.+)$ ^products.php?id=$1$ [L]
        

    Understanding Rewrite Rules

    • RewriteBase: It assists in stripping the base and applying regex to the remaining URL, ensuring the .htaccess file remains at the root directory.
    • RewriteCond: This directive matches the test string against a pattern, enabling conditional rewriting based on factors like query strings, file existence, and HTTP headers.
    • RewriteRule: Defines the actual rewriting logic by rewriting the URL based on defined patterns and conditions. It includes modifiers for permanent or temporary redirections, case insensitivity, and rule termination.