none
Where should internal links point if using URL rewriting with .htaccess file? RRS feed

  • Question

  • I am rewriting URLs to remove the .php extension, so “foo.php” is displayed as “foo” in browser.

    When using the Expression Web preview, my internal links will only resolve “foo.php”, and not “foo” since I don’t have .htaccess file internally.  Is there way to mimic the server htaccess locally in Expression Web preview?  Or should my internal links just point to foo.php?  I have the PHP run running locally and working in Expression Web, but do not have full local server installed.

    Friday, September 28, 2012 6:17 PM

Answers

  • Vegan, do you even know what URL rewrite does?

    It tells the server how to parse files with or without a specific file extension in lieu of the default behavior for files. URL rewrite is all on the host server and has absolutely nothing to do with what an ISP does or does not do. Nor does it have anything to do with the browser since all it gets is html, css and images.

    That is why EW doesn't understand and resolve internally links without the file extension because neither EW nor the Cassini testing server know about the url rewriting that occurs on the hosting server. So you have to manually create your links and then publish them to a server that has the url rewrite properly configured on it for testing. This is such atypical behavior that EW cannot understand what the OP is doing and frankly, shouldn't have to since using url rewrite in this manner is poor web architecture practice.


    Free Expression Web Tutorials
    For an Expression Web forum with without the posting issues try expressionwebforum.com

    • Marked as answer by John Trone Sunday, September 30, 2012 9:57 PM
    Saturday, September 29, 2012 4:36 PM
  • John, I'm afraid that I'm going to have to agree with Bill on this one. The reason I asked you what your actual objective was is because I could discern no advantage to be gained from stripping the extensions from URL resources. I still cannot. In fact, as Bill noted, it makes impossible even the most basic, common operations, such as copying and pasting a URL into an email or forum post, or EverNote, or Palm Desktop, or...

    Furthermore, I have investigated the reference that you provided to explain your reasoning, and from what I can read, it does not mean what you seem to think it means. According to that page, "clean URLs" are "... purely structural URLs that do not contain a query string and instead contain only the path of the resource."

    Note the thrust of that definition. It has nothing whatsoever to do with removing the extensions from resource files in URLs. It has to do with eliminating the tortuous querystring-laden URLs commonly generated by tools such as blogs and CMS engine. It emphasizes "purely structural URLs" which "contain only the path of the resource." By that definition, URLs such as your example, http://www.cnn.com/feedback/, even if you add a filename with extension, as in http://www.cnn.com/feedback/index.php, easily meet the definition of a clean URL, since they are "purely structural URLs" which "contain only the path of the resource." It says nothing about the extension.

    In fact, one of the examples on that page, http://example.com/news.rss, explicitly shows the extension in place in the "cleaned" URL. Furthermore, two of the "cleaned" URLs in the examples, http://example.com/kb/8/41 and http://example.com/profiles/193, are at least as cryptic as anything I've ever encountered containing a filename complete with extension.

    John, there is no reason whatsoever to go to all that trouble to attain an objective which is questionable at best, and which is demonstrably not what that reference intended to promote, and particularly when it detracts from site usability, and, not incidentally, hoses EW's ability to manage your site for you, or even to preview your site correctly. If you ever decide to change languages, no sweat. A single, simple 301 mod_rewrite to redirect all "php" extensions to "aspx" (for example) and you're done. There are lots more productive avenues you can explore for your site. You might want to give this one a rest. Think about it...

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    • Marked as answer by John Trone Monday, October 1, 2012 11:27 PM
    Monday, October 1, 2012 5:05 AM

All replies

  • No, and personally I wouldn't use url rewrite to remove the file extension. While it isn't as common as it once was some ISPs will cache pages with html extensions or no extension (aka where a default page is shown in a folder) but do not cache php or other dynamic file extensions. AOL and other ISPs that brag about "accelerated" page rendering are the ones who most commonly cache pages instead of sending the most recent version of the page.

    Free Expression Web Tutorials
    For an Expression Web forum with without the posting issues try expressionwebforum.com

    Friday, September 28, 2012 6:26 PM
  • Vegan, do you even know what URL rewrite does?

    It tells the server how to parse files with or without a specific file extension in lieu of the default behavior for files. URL rewrite is all on the host server and has absolutely nothing to do with what an ISP does or does not do. Nor does it have anything to do with the browser since all it gets is html, css and images.

    That is why EW doesn't understand and resolve internally links without the file extension because neither EW nor the Cassini testing server know about the url rewriting that occurs on the hosting server. So you have to manually create your links and then publish them to a server that has the url rewrite properly configured on it for testing. This is such atypical behavior that EW cannot understand what the OP is doing and frankly, shouldn't have to since using url rewrite in this manner is poor web architecture practice.


    Free Expression Web Tutorials
    For an Expression Web forum with without the posting issues try expressionwebforum.com

    • Marked as answer by John Trone Sunday, September 30, 2012 9:57 PM
    Saturday, September 29, 2012 4:36 PM
  • This is interesting because on: Saturday, September 29, 2012 at 2:36 AM
    I was in bed sound asleep.


    Expression Web MVP

    Sunday, September 30, 2012 7:04 PM
  • This is interesting because on: Saturday, September 29, 2012 at 2:36 AM
    I was in bed sound asleep.


    Expression Web MVP

    Interesting. Are you saying that you didn't post that, or that the forum software (surprise!) screwed up the timestamp for the post? If the former, whew! compromised credentials? If the latter, well, no real surprise there. I've learned not to be surprised by anything this forum software comes up with.

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    Sunday, September 30, 2012 7:39 PM
  • Cheryl, thanks, that answered my question about EW, and I know my options, either not rewrite, or put up a full test server.  When you say doing url rewrite in this manner is poor web architecture practice, are you opposed to any URL rewriting or just saying the method I was using was poor? 
    Sunday, September 30, 2012 9:26 PM
  • John, I don't understand why you are using the rewrite at all. What is your reason for doing so? I've never done anything like this, but from your description, it would seem that it would prevent EW from adjusting URLs for assets moved internally. What is your actual objective, and why do you feel that using mod_rewrite is the best approach?

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    Sunday, September 30, 2012 11:47 PM
  • Thanks Scott, I was considering rewrite to provide clean URLs for the end user.  For the end user, .php does not add anything.  For instance, http://www.cnn.com/feedback/ is a cleaner url than adding a .php or .aspx to the url.  Also if I ever change scripting languages on site, it is easier to move without having to create a bunch of redirects for old URLs.  I am not sure if mod_rewrite is best approach.  My question was answered though, so I will decide if it is worth the effort to setup dev server to test URLs or just skip it and go with .php extensions.  Wikipedia is good example of PHP site where all the URLs are written or rewritten without PHP extension.
    Monday, October 1, 2012 12:16 AM
  • @Vegan, yes, it could be a folder with a index or default file, but it was just an example; I don't know for sure how they do their implementation.  There are lots of sites using clean URLs.  Here is another example and article on some of the reasoning:    http://en.wikipedia.org/wiki/Clean_URL 
    Monday, October 1, 2012 1:05 AM
  • John: I'm not trying to be a smart *****, but who cares about the URL except you? Nobody.

    The visitor doesn't care. They don't use the URL nor even look at it; they use the back/forward arrows and the menus. I'd be surprised if 1 in 100 ever looked at it.

    If the visitor did ever want to use the URL (for putting a link in an e-mail or something), they do need to be able to just copy and paste the real URL--not http://www.cnn.com/feedback/ , for the sake of usability of the recipient.

    I think I'd forget about that rewriting, given the potential downsides.


    It's not the heat, it's the stupidity.


    Monday, October 1, 2012 2:36 AM
  • Vegan, with respect to this (to which you were replying):

    "For instance, http://www.cnn.com/feedback/ is a cleaner url than adding a .php or .aspx to the url."

    Your reply:

    "That type of URL means a sub folder for a sub site, where index.php is implied"

    is hogwash. It means nothing of the kind. "Feedback" is certainly a subdirectory of the site root, but it is not a subdomain, which has a specific meaning, and which would precede the domain name and TLD (as in feedback.cnn.com). As for "subsite," that has a different meaning depending upon whether you're talking about FrontPage/EW (where "...a subsite is a subfolder containing a stand-alone site"—from EW's User Guide), Websphere, Drupal, Sharepoint, or other environments where it is a term of art specific to the particular environment, with meaning peculiar only to that environment.


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    Monday, October 1, 2012 3:55 AM
  • John, what I was saying is that removing the file extension when the page is sent to the browser is poor website architecture. There are good reasons why pages have file extension to do with static vs dynamically rendered page caching and SEO.

    I'm not opposed to all url rewriting and have done it myself on occasion. Those occasions primarily have to do with SEO and bookmarking. They occur either when I already have am html based website that has grown to where it needs server side process such as a brochure site that is now selling products so has forms to process on each page. Using a combination of url rewrite and server configuration files I'll set the server to parse .html as php or asp.net but that is something to be used sparingly on high volume sites since it can burden the server.

    Another use will be in blogs and other cms systems where I want a user friendly and seo friendly url instead of http://site.tld/page.php?m=579845667 it will be http://site.tld/category/page-title.php.

    Your wikipedia example would be one that uses a CMS and is rewriting for SEO purposes from database generated pages to make the link easier to remember not to omit the file extension. If you aren't using a database to generate urls. It is better to create your site in a way that makes sense to a visitor using good naming conventions. That's what wikipedia is emulating with the url rewriting.


    Free Expression Web Tutorials
    For an Expression Web forum with without the posting issues try expressionwebforum.com



    Monday, October 1, 2012 4:12 AM
  •  Also if I ever change scripting languages on site, it is easier to move without having to create a bunch of redirects for old URLs.  I am not sure if mod_rewrite is best approach. 

    You don't need to do individual redirects for each page if you change file extensions. Take a look at http://forums.digitalpoint.com/showthread.php?t=114547 for a couple of options on how to redirect from one file extension to another if you ever change.


    Free Expression Web Tutorials
    For an Expression Web forum with without the posting issues try expressionwebforum.com

    Monday, October 1, 2012 4:23 AM
  • John, I'm afraid that I'm going to have to agree with Bill on this one. The reason I asked you what your actual objective was is because I could discern no advantage to be gained from stripping the extensions from URL resources. I still cannot. In fact, as Bill noted, it makes impossible even the most basic, common operations, such as copying and pasting a URL into an email or forum post, or EverNote, or Palm Desktop, or...

    Furthermore, I have investigated the reference that you provided to explain your reasoning, and from what I can read, it does not mean what you seem to think it means. According to that page, "clean URLs" are "... purely structural URLs that do not contain a query string and instead contain only the path of the resource."

    Note the thrust of that definition. It has nothing whatsoever to do with removing the extensions from resource files in URLs. It has to do with eliminating the tortuous querystring-laden URLs commonly generated by tools such as blogs and CMS engine. It emphasizes "purely structural URLs" which "contain only the path of the resource." By that definition, URLs such as your example, http://www.cnn.com/feedback/, even if you add a filename with extension, as in http://www.cnn.com/feedback/index.php, easily meet the definition of a clean URL, since they are "purely structural URLs" which "contain only the path of the resource." It says nothing about the extension.

    In fact, one of the examples on that page, http://example.com/news.rss, explicitly shows the extension in place in the "cleaned" URL. Furthermore, two of the "cleaned" URLs in the examples, http://example.com/kb/8/41 and http://example.com/profiles/193, are at least as cryptic as anything I've ever encountered containing a filename complete with extension.

    John, there is no reason whatsoever to go to all that trouble to attain an objective which is questionable at best, and which is demonstrably not what that reference intended to promote, and particularly when it detracts from site usability, and, not incidentally, hoses EW's ability to manage your site for you, or even to preview your site correctly. If you ever decide to change languages, no sweat. A single, simple 301 mod_rewrite to redirect all "php" extensions to "aspx" (for example) and you're done. There are lots more productive avenues you can explore for your site. You might want to give this one a rest. Think about it...

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    • Marked as answer by John Trone Monday, October 1, 2012 11:27 PM
    Monday, October 1, 2012 5:05 AM
  • Thanks everyone, I marked this as answered.
    Monday, October 1, 2012 11:27 PM
  • "John, I'm afraid that I'm going to have to agree with Bill on this one."

    Afraid? Afraid?

    Harrumph!

    ;-)


    It's not the heat, it's the stupidity.

    Tuesday, October 2, 2012 3:57 AM