Welcome Guest, Not a member yet? Register   Sign In
redirect a PHP suffix to a controller using Apache mod_rewrite / RewriteRule
#1

[eluser]tmcallister[/eluser]
Folks.

I am dealing with a client application that must post to a URL with a suffix. For example: post_here.php

I want to redirect this to a controller, lets say: www.mydomain.com/receive

It seems if I were to add the following to htaccess, this RewriteRule should work:

Code:
RewriteRule ^post_here.php$ /receive/

however, I am getting no joy here.

Any thoughts? TIA
#2

[eluser]tmcallister[/eluser]
Actually, I think I see part of the problem. Perhaps I need to route this through the index.php file like so:

Code:
RewriteRule ^post_here.php$ /index.php/receive/

This makes sense, but now I am getting a "no input file specified" message in the browser...
#3

[eluser]tmcallister[/eluser]
At the moment, it looks like this will work:

Code:
RewriteRule ^post_here.php$ http://mydomain.com/receive/

I'll try posting for real and see...
#4

[eluser]tmcallister[/eluser]
[quote author="tmcallister" date="1253695645"]At the moment, it looks like this will work:

Code:
RewriteRule ^post_here.php$ http://mydomain.com/receive/

I'll try posting for real and see...[/quote]

Well....

The code above redirects, but not in a usable manner. It seems this is an an external redirection, changing the URL, and doesn't work for my needs.

I need to do an internal rewrite, so the url stays the same. For example, with the following rule, the URL "start.php" will display start.php in the URL address, but display the result of "end.php"

Code:
RewriteRule ^start.php$ end.php

How can I achieve the same thing when redirecting a "*.php" file to a CI controller?

thanks
#5

[eluser]tmcallister[/eluser]
No ideas?? Do I need to offer a reward or payment for an answer? :-)

How about $10 via PayPal to anyone who can solve this problem?
#6

[eluser]bretticus[/eluser]
Instead of using redirect, why not just configure CI to use the php extension? See Adding a URL Suffix

If that will not work for you, you might get better mileage with CI's URI Routing.

If you prefer a mod_rewrite rule, you might try this (untested.)
Code:
RewriteRule ^post_here.php$ index.php?/receive/index [L]
#7

[eluser]tmcallister[/eluser]
[quote author="bretticus" date="1253740230"]Instead of using redirect, why not just configure CI to use the php extension? See Adding a URL Suffix

If that will not work for you, you might get better mileage with CI's URI Routing.

If you prefer a mod_rewrite rule, you might try this (untested.)
Code:
RewriteRule ^post_here.php$ index.php?/receive/index [L]
[/quote]

Thanks for taking the time to respond. Great points you make.

URL Suffix:
I am addressing a single integration point in a complex system. I don't want to force a URL suffix site wide to accommodate a single integration point.

Routing:
I started looking at routing 30 minutes ago. I don't find any documentation or examples that address the use of a php suffix, but I am still looking at it.

mod_rewrite
Unfortunately, I tried several variations of your suggested RewriteRule, each resulting in a 404 or no input file specified.


Thanks for your suggestions!
#8

[eluser]bretticus[/eluser]
I never used the suffix feature before so I thought it was optional. Smile

Okay, so I got stubborn and made this work:


Code:
RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    RewriteRule ^post_here.php$ /index.php?/user/journal [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

The difference was putting it above the exceptions for accessing a real file or directory. NOTE: this is part of my apache config (not .htaccess) your mileage may vary.
#9

[eluser]tmcallister[/eluser]
[quote author="bretticus" date="1253744936"]I never used the suffix feature before so I thought it was optional. Smile

Okay, so I got stubborn and made this work:


Code:
RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    RewriteRule ^post_here.php$ /index.php?/user/journal [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

The difference was putting it above the exceptions for accessing a real file or directory. NOTE: this is part of my apache config (not .htaccess) your mileage may vary.[/quote]


Previously I tried putting it above the exceptions with no luck, but let me thoughtfully review your suggestion here. Thanks, I'll report back later today.
#10

[eluser]tmcallister[/eluser]
@bretticus, haven't forgotten about you or the reward :-) just haven't had time to get back to it. I will asap.
thx




Theme © iAndrew 2016 - Forum software by © MyBB