Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-13-2012, 08:13 AM   PM User | #1
Rahul_nesarikar
New to the CF scene

 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rahul_nesarikar is an unknown quantity at this point
Question htaccess rule to redirect to a script

Hi Everyone

I'm trying to write an .htaccess rule to redirect to a script, which further redirects somewhere else. However, I don't want the address url to change during the .htaccess part of the redirect.


Example:
test.mytest.com/page/test/hello
this page should be hanlded by test.mytest.com/environment_test.php
but test.mytest.com/page/test/hello still appears in browser.


Thanks for reply in advance
Rahul_nesarikar is offline   Reply With Quote
Old 06-13-2012, 03:54 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Not a thing to do with PHP. Moving to Apache configurations.

If you issue a redirect, it will follow it. Use rewrite if you don't want to make the url appear to change. Not sure how you want to formulate the matching, with the example you have here a simple:
Code:
RewriteEngine On
RewriteRule /page/test/hello$ environment_test.php
Is sufficient.
Fou-Lu is offline   Reply With Quote
Old 06-13-2012, 04:17 PM   PM User | #3
csammy
New to the CF scene

 
Join Date: Jan 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
csammy is an unknown quantity at this point
I'm working with Rahul on this...

1) URL rewrite is what we want, thanks for clarifying.

2) Let's say we want all pages, after the domain name to be handled by environment_test.php. How would you update your htaccess for that?

Meaning, we want...

test.mytest.com/page/test/hello
test2.mytest.com/page/test/hello/1234
test2.mytest2.com/different

...all to be handled by environment_test.php. The application will take it from there in terms of producing an output.

3) Then, how would we throw in an exception? Say we have a file that if it is accessed in the URL, we want it to this to actually load the file they're requesting. For example...

test.mytest.com/app/run.php

Can we make it so anything in the /app/ folder will actually run if the file being requested (run.php) exists?

4) Lastly, we will use this for dev/staging/production - can we insert a wildcard for the domains?


Thanks!
csammy is offline   Reply With Quote
Old 06-15-2012, 06:53 PM   PM User | #4
csammy
New to the CF scene

 
Join Date: Jan 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
csammy is an unknown quantity at this point
any help here?
csammy is offline   Reply With Quote
Old 06-18-2012, 04:05 PM   PM User | #5
csammy
New to the CF scene

 
Join Date: Jan 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
csammy is an unknown quantity at this point
anyone?
csammy is offline   Reply With Quote
Old 06-19-2012, 04:21 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You can use RewriteCond to determine if the requested is a directory or a file. What would probably work is a:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
And proceed with your matching rules. That should only apply the rewrite rules so long as the requested file is not an actual file.

For domains, you can also use the RewriteCond to match hosts. This would allow a one line swap when you change a domain.

I hope that helps some, I'm not an apache wizard but I can typically stumble my way through.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:41 PM.


Advertisement
Log in to turn off these ads.