Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Url Rewriting

Url Rewriting

Scheduled Pinned Locked Moved Web Development
tutorialquestionphpapache
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Danzy83
    wrote on last edited by
    #1

    I beginning how to use url rewriting. Now I have this rule in apache (an example) which works fine: RewriteEngine On RewriteRule ^register$ register.php I have also learnt that in order for the rule to accept an ending slash (localhost/register/), the rule should be changed to:

    RewriteRule ^register/?$ register.php

    This also loads the register.php page when it is accessed through (http://localhost/register) but when I add the trailing slash (http://localhost/register/), my stylesheet which is in a different directory is not applied in formatting the page. The page thus loads without any formatting.

    How can I ensure that the stylesheet is used in formatting the page when there is a forward slash at the end? It is possible for a user to add the slash at the end and so I would like to know a solution. Thanks.

    D 1 Reply Last reply
    0
    • D Danzy83

      I beginning how to use url rewriting. Now I have this rule in apache (an example) which works fine: RewriteEngine On RewriteRule ^register$ register.php I have also learnt that in order for the rule to accept an ending slash (localhost/register/), the rule should be changed to:

      RewriteRule ^register/?$ register.php

      This also loads the register.php page when it is accessed through (http://localhost/register) but when I add the trailing slash (http://localhost/register/), my stylesheet which is in a different directory is not applied in formatting the page. The page thus loads without any formatting.

      How can I ensure that the stylesheet is used in formatting the page when there is a forward slash at the end? It is possible for a user to add the slash at the end and so I would like to know a solution. Thanks.

      D Offline
      D Offline
      Danzy83
      wrote on last edited by
      #2

      Well I realised that even when I type the actual page in the address bar with the ending forward slash, the page loads without formatting. This means the problem is not with the RewriteRule. Is there a way to solve this problem when the requested page ends in a slash (http://localhost/register.php/) so that the stylesheet is applied? Thanks.

      A 1 Reply Last reply
      0
      • D Danzy83

        Well I realised that even when I type the actual page in the address bar with the ending forward slash, the page loads without formatting. This means the problem is not with the RewriteRule. Is there a way to solve this problem when the requested page ends in a slash (http://localhost/register.php/) so that the stylesheet is applied? Thanks.

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #3

        You are probably using a relative path to refer to your style sheet. When your URL is register.php, that is considered a page. When your URL is register.php/, that is considered a directory one level deeper than the directory of register.php. If you use an absolute path, you don't need to worry about that. Example:

        /css/main.css

        Alternatively, you can create a redirect rule (not the same as a rewrite) for when there is a trailing slash and have it redirect to the page without the trailing slash, avoiding the issue entirely.

        Thou mewling ill-breeding pignut!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups