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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
"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. |