Forum Moderators: phranque

Message Too Old, No Replies

add more condition for more result

         

webstyler

1:10 pm on Mar 5, 2007 (gmt 0)

10+ Year Member



Hi, I use this in my htaccess

RewriteEngine on

AddType application/x-httpd-php .php .html

RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^.]+)\.html$ mypage.php?name=$1 [QSA,L]

--------

Now I need to add 2 more thing:
1. the file call can be htm and not only html
2. the file call can haven't extension

So:

example.html
or
example.htm
or
example << if NOT a dir

must be rewrite to mypage.php?name=...

How to make this?

Thanks

phranque

1:28 pm on Mar 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



try this:
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^.]+)(\.html?)?$ mypage.php?name=$1 [QSA,L]

the "-f" insures it is not a directory.
the "?" and "()" i added makes the ".html" optional and within that the "l" is optional.

webstyler

7:01 pm on Mar 5, 2007 (gmt 0)

10+ Year Member



RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^.]+)(\.html?)?$ constructor.php?name=$1 [QSA,L]

:)

example.html > ok
example.htm > ok
example without extension > ok

example. > ok << if possible to not rewrite this?

with a dir there is any problem, I can't open dir as
images/

tx x help

jdMorgan

8:14 pm on Mar 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# if requested URI does not exist as a real file
RewriteCond %{REQUEST_FILENAME} !-f
# and if requested URI does not exist as a real directory
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite .htm, .html, or extensionless URIs to constructor.php
RewriteRule ^([^.]+)(\.html?)?$ constructor.php?name=$1 [QSA,L]

Jim

webstyler

12:08 pm on Mar 6, 2007 (gmt 0)

10+ Year Member



Hi Jim, is perfect :)

only 1 thing.. if possible

can not rewrite for page.?

page.html yes
page.htm yes
page yes
page. << now yes but would like not rewrite (as page.h or page.ht)

Thks x help

webstyler

12:29 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



uhm

is possible to add 1 more control as when page call withou extension as

user digit
example

if > if exist example.html
then > rewrite to this
else > rewrite to constructor

?

tx

jdMorgan

3:51 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm sorry, but I don't understand what you are trying to ask here.

Jim

webstyler

4:09 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



:) sorry

I try to explain better

This is code that you have suggest, that is perfect :)

# if requested URI does not exist as a real file
RewriteCond %{REQUEST_FILENAME}!-f
# and if requested URI does not exist as a real directory
RewriteCond %{REQUEST_FILENAME}!-d
# rewrite .htm, .html, or extensionless URIs to constructor.php
RewriteRule ^([^.]+)(\.html?)?$ constructor.php?name=$1 [QSA,L]

at this time:

user digit example
if example not exist is rewrite with constructor

I need to add this check

user digit example
if example exist ok
if example not exist:
--> check if exist example.html
--> if yes rewrite to example.html
else (if example and example.html not exist) rewrite to constructor.php

I need to add only 1 chek before rewrite tha redirect (if exist .html) to him

Thks

jdMorgan

4:31 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, you'll need to add a new rule above the existing one, then:

# if requested URI does not exist as a real file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# but does exist as a file with ".html" appended
RewriteCond %{REQUEST_FILENAME}.html -f
# then rewrite extensionless URI to .html file
RewriteRule ^([^.]+)$ $1.html [L]
#
# if requested URI does not exist as a real file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite .htm, .html, or extensionless URIs to constructor.php
RewriteRule ^([^.]+)(\.html?)?$ constructor.php?name=$1 [QSA,L]

Jim

[edited by: jdMorgan at 4:32 pm (utc) on Mar. 14, 2007]

webstyler

7:32 pm on Mar 15, 2007 (gmt 0)

10+ Year Member




UAO :D

really perfect

thank you very match jdMorgan :)