Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Mod rewrite help? f.php to /f

(216 views • 9 replies)

This topic is 1 page long.

<< < > >>
None

yhar

Reply To Post Reply & Quote

Posted at: 5/4/08 05:27 PM

yhar NEUTRAL LEVEL 03

Sign-Up: 04/02/08

Posts: 758

Hi,
I have "domain.com"
I have "domain.com/file.php"
I want "domain.com/file" to redirect to "domain.com/file.php"
I want this for every file, not just ones i set manually.

I have it atm so i can set them manually, but I want it automatic, adding manually is a pain.
What's the mod_rewrite code?

Much appreciated darlings <3

BBS Signature

None

smulse

Reply To Post Reply & Quote

Posted at: 5/4/08 05:57 PM

smulse EVIL LEVEL 28

Sign-Up: 03/24/05

Posts: 4,948

At 5/4/08 05:27 PM, yhar wrote: <3
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

None

yhar

Reply To Post Reply & Quote

Posted at: 5/4/08 06:24 PM

yhar NEUTRAL LEVEL 03

Sign-Up: 04/02/08

Posts: 758

At 5/4/08 05:57 PM, smulse wrote:
At 5/4/08 05:27 PM, yhar wrote: <3

I love you, ty ty ty ty ty ty./

BBS Signature

None

smulse

Reply To Post Reply & Quote

Posted at: 5/4/08 06:35 PM

smulse EVIL LEVEL 28

Sign-Up: 03/24/05

Posts: 4,948

At 5/4/08 06:24 PM, yhar wrote:
At 5/4/08 05:57 PM, smulse wrote:
At 5/4/08 05:27 PM, yhar wrote: <3
I love you, ty ty ty ty ty ty./

M Mh M M
Everybody does
You can be in the weekend of yours
To see what you get into

Make love and listen to the music
You've gotta let yourself go go go go go oh

I like to party mmhmm
Everybody does
You can be in the weekend of yours
To see what you get into

Make love and listen to the music
You've gotta let yourself go ooh ooh ooh ooh

Gotta get myself
Gotta move on up
Make love until the morning now

Make love and listen to the music
You've gotta let yourself go go go go go oh


None

yhar

Reply To Post Reply & Quote

Posted at: 5/4/08 06:52 PM

yhar NEUTRAL LEVEL 03

Sign-Up: 04/02/08

Posts: 758

At 5/4/08 06:35 PM, smulse wrote:

I'm sitting here in the boring room
It's just another rainy Sunday afternoon
I'm wasting my time
I got nothing to do
I'm hanging around
I'm waiting for you
But nothing ever happens and I wonder

I'm driving around in my car
I'm driving too fast
I'm driving too far
I'd like to change my point of view
I feel so lonely
I'm waiting for you
But nothing ever happens and I wonder

I wonder how
I wonder why
Yesterday you told me 'bout the blue blue sky
And all that I can see is just a yellow lemon-tree
I'm turning my head up and down
I'm turning turning turning turning turning around
And all that I can see is just another lemon-tree

I'm sitting here
I miss the power
I'd like to go out taking a shower
But there's a heavy cloud inside my head
I feel so tired
Put myself into bed
Well, nothing ever happens and I wonder

Isolation is not good for me
Isolation I don't want to sit on the lemon-tree

I'm steppin' around in the desert of joy
Baby anyhow I'll get another toy
And everything will happen and you wonder

I wonder how
I wonder why
Yesterday you told me 'bout the blue blue sky
And all that I can see is just another lemon-tree
I'm turning my head up and down
I'm turning turning turning turning turning around
And all that I can see is just a yellow lemon-tree
And I wonder, wonder

I wonder how
I wonder why
Yesterday you told me 'bout the blue blue sky
And all that I can see, and all that I can see, and all that I can see
Is just a yellow lemon-tree

BBS Signature

Shouting

RIPCGeek

Reply To Post Reply & Quote

Posted at: 5/4/08 07:17 PM

RIPCGeek FAB LEVEL 03

Sign-Up: 04/19/08

Posts: 111

....What just happened here?

BBS Signature

None

DannyIsOnFire

Reply To Post Reply & Quote

Posted at: 5/5/08 06:56 AM

DannyIsOnFire DARK LEVEL 16

Sign-Up: 04/14/05

Posts: 5,847

At 5/4/08 07:17 PM, RIPCGeek wrote: ....What just happened here?

Insania!

BBS Signature

None

Rob

Reply To Post Reply & Quote

Posted at: 5/5/08 11:54 AM

Rob NEUTRAL LEVEL 02

Sign-Up: 03/15/08

Posts: 7

I strongly recommend that all PHP developers build their sites with a front controller - i.e., one script that all hits are redirected to. Then that script can read the incoming URL and load the correct pages. To do this, you use a redirect like the following:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]

Then, in index.php, you can get the url with
$url = $_SERVER['REQUEST_URI'];

I have found that this method saves me time even on sites with only a couple pages.

-Rob

At 5/4/08 05:27 PM, yhar wrote: Hi,
I have "domain.com"
I have "domain.com/file.php"
I want "domain.com/file" to redirect to "domain.com/file.php"
I want this for every file, not just ones i set manually.

I have it atm so i can set them manually, but I want it automatic, adding manually is a pain.
What's the mod_rewrite code?

Much appreciated darlings <3

None

yhar

Reply To Post Reply & Quote

Posted at: 5/5/08 12:42 PM

yhar NEUTRAL LEVEL 03

Sign-Up: 04/02/08

Posts: 758

Of course that should be done with a small site, with minimal php pages, but with a larger site with a lot of pages, it's much easier to have many pages and simply use header and footer includes...

BBS Signature

None

Rob

Reply To Post Reply & Quote

Posted at: 5/5/08 02:57 PM

Rob NEUTRAL LEVEL 02

Sign-Up: 03/15/08

Posts: 7

I could not disagree more. You just use a simple algorithm to transform a url into a page. That way, you can add logic to every page or only some pages from a single, centralized place. This becomes more important as a site grows. That's why every major framework uses a front controller. Believe me, you don't want to have to use mod_rewrite to change individual URLs, you don't want to have to add validation logic piecemeal, and you don't want to be restricted to modifications at the top and bottom of every page. I could go on and on about the advantages of a front-controller architecture, but if you want to know more, there's always Google.

At 5/5/08 12:42 PM, yhar wrote: Of course that should be done with a small site, with minimal php pages, but with a larger site with a lot of pages, it's much easier to have many pages and simply use header and footer includes...

All times are Eastern Daylight Time (GMT -4) | Current Time: 09:44 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!