Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rewrite rule

         

Mark1978

10:56 am on May 20, 2010 (gmt 0)

10+ Year Member



Hi,
I need to re-write a url on a website I have been working so that it conforms to the rest of the site:

http://www.example.com/showreel/index/php

To

[example.com...]

Does anyone know how the best to achieve this?

Thanks

g1smd

11:50 am on May 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you mean rewrite, or do you mean redirect?

They are very different things, even if the code only differs by a few characters.

Let's see your code, and details as to what happens when you use it.

Mark1978

1:06 pm on May 20, 2010 (gmt 0)

10+ Year Member



Hi Sorry, I probably need to be a bit clearer.

It needs to be a rewrite. As shown below

http://www.example.com/showreel/index/php To http://www.example.com/4-showreel.html

The showreel section that I created is not dynamically created by the CMS. Hence that's why it has a different url. The sections are numbered and named by the CMS and then given a .html extension via .htaccess

Does this make sense? I just want it follow the same convention as the rest of the site.

Thanks

jdMorgan

2:12 pm on May 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Part of the confusion is mixing-up URLs (used out on the Web) with filepaths (used inside the server).

Another part of the confusion is this, specifically the italicized part:
> The sections are numbered and named by the CMS and then given a .html extension via .htaccess

.htaccess does not and cannot do this as described. What .htaccess can do is to take a client request for the client-requested URL http://www.example.com/4-showreel.html and rewrite that request to the script filepath /showreel/index.php (note no protocol or domain on filepath).

So step one is to modify the links and object references on your pages to refer to .html URLs, and step two is to write a rewriterule to "connect" those URLs to the script file at /showreel/index.php

An optional step three is to redirect direct client requests for the script filepath (filepath used as a URL) to the correct .html URL. This must be done last, after everything else is tested and working.

And finally, an additional option is to get rid of the superfluous ".html" extensions on your URLs, since they do nothing whatsoever out on the Web but waste bytes. Extensionless URLs such as http://www.example.com/4-showreel would work just fine.

Anyway, the bottom line is that whatever URL you want to appear in the browser address bar and in search engine results listings is the URL you must link to on your pages. Pages define URLs, and once a URL is published, mod_rewrite in .htaccess cannot change it.

Jim