Rewriting question

This is a discussion on Rewriting question within the Apache Web Server forums, part of the Web Server and Related Forums category; Hello, I would like to have my website accessed just by the filenames without their extension, especially for the php ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-14-2008
syn_nospam_uw
 
Posts: n/a
Default Rewriting question

Hello,

I would like to have my website accessed just by the filenames without
their extension, especially for the php pages. So let's say I access the
page www.website.tld/mypage then it will redirect me to
www.website.tld/mypage.php. How can I do this with the rewrite rule ?

Thanks for your help

Regards
  #2 (permalink)  
Old 05-14-2008
Luuk
 
Posts: n/a
Default Re: Rewriting question

syn_nospam_uw schreef:
> Hello,
>
> I would like to have my website accessed just by the filenames without
> their extension, especially for the php pages. So let's say I access the
> page www.website.tld/mypage then it will redirect me to
> www.website.tld/mypage.php. How can I do this with the rewrite rule ?
>
> Thanks for your help
>
> Regards


Its almost as in the example on:
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

--
Luuk
  #3 (permalink)  
Old 05-14-2008
syn_nospam_uw
 
Posts: n/a
Default Re: Rewriting question

Luuk wrote:

> Its almost as in the example on:
> http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html


Thanks I had a look and made up the following rewrite rule:

RewriteRule ^([^.]+)$ $1.php [redirect=301]

Unfortunately this doesn't work when the / page gets called as when I
enter www.domain.tld it rewrites it to www.domain.tld/.php the same
problem arises with accessing subdirectories of the webroot.

Does anyone have an idea how I can fix this ?

Regards
  #4 (permalink)  
Old 05-14-2008
Luuk
 
Posts: n/a
Default Re: Rewriting question

syn_nospam_uw schreef:
> Luuk wrote:
>
>> Its almost as in the example on:
>> http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

>
> Thanks I had a look and made up the following rewrite rule:
>
> RewriteRule ^([^.]+)$ $1.php [redirect=301]
>
> Unfortunately this doesn't work when the / page gets called as when I
> enter www.domain.tld it rewrites it to www.domain.tld/.php the same
> problem arises with accessing subdirectories of the webroot.
>
> Does anyone have an idea how I can fix this ?
>
> Regards



stop rewriting things that end with a '/' (not tested, because this
man-page (http://www.pcre.org/pcre.txt) is sooo long ;-)

RewriteRule ^([^.]+)[^/]$ $1.php [redirect=301]

--
Luuk
  #5 (permalink)  
Old 05-14-2008
syn_nospam_uw
 
Posts: n/a
Default Re: Rewriting question

Luuk wrote:

> stop rewriting things that end with a '/' (not tested, because this
> man-page (http://www.pcre.org/pcre.txt) is sooo long ;-)
>
> RewriteRule ^([^.]+)[^/]$ $1.php [redirect=301]


I had a quick try at it and from the concept it's good but unfortunately
it somehow removes the last letter from the url: so if I enter for
example www.domain.tld/apage it gets rewritted like this:
www.domain.tld/apag

note the missing "e" at the end...

Strange behavior... Any other guesses ?

Regards


  #6 (permalink)  
Old 05-14-2008
Luuk
 
Posts: n/a
Default Re: Rewriting question

syn_nospam_uw schreef:
> Luuk wrote:
>
>> stop rewriting things that end with a '/' (not tested, because this
>> man-page (http://www.pcre.org/pcre.txt) is sooo long ;-)
>>
>> RewriteRule ^([^.]+)[^/]$ $1.php [redirect=301]

>
> I had a quick try at it and from the concept it's good but unfortunately
> it somehow removes the last letter from the url: so if I enter for
> example www.domain.tld/apage it gets rewritted like this:
> www.domain.tld/apag
>
> note the missing "e" at the end...
>
> Strange behavior... Any other guesses ?
>
> Regards
>
>


yes, my last answer was wrong.....

you should rewrite:
www.exmple.com/test ==> www.exmple.com/test.php
and
www.exmple.com/test/ ==> www.exmple.com/test/index.php

start reading http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
again ;-)

i know i have to read them some day too.... ;-)
(but only when i find the need to use it meself...!)

--
Luuk
  #7 (permalink)  
Old 05-14-2008
D. Stussy
 
Posts: n/a
Default Re: Rewriting question

"syn_nospam_uw" <syn_nospam_uw@hotmail.com> wrote in message
news:843a7$482ad356$d9a276b1$11393@news.hispeed.ch ...
> I would like to have my website accessed just by the filenames without
> their extension, especially for the php pages. So let's say I access the
> page www.website.tld/mypage then it will redirect me to
> www.website.tld/mypage.php. How can I do this with the rewrite rule ?
>
> Thanks for your help


Why use rewrite? Use "Option Multiviews". See content negotiation.


  #8 (permalink)  
Old 05-15-2008
syn_nospam_uw
 
Posts: n/a
Default Re: Rewriting question

D. Stussy wrote:

> Why use rewrite? Use "Option Multiviews". See content negotiation.


cool, mod_negotiation made my day ;-) works perfectly!

Regards
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:00 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0