Link to home
Create AccountLog in
Avatar of stargateatlantis
stargateatlantis

asked on

mod_rewrite php

Using mod_rewrite with the following link below

http://www.mydomain.com/authorize/index.php?key=1234

would be re-written like this

http://www.mydomain.com/authorize/index.php/key/1234

But the problem in php is that the 1234 could be a different key how would mod_rewrite work on that
SOLUTION
Avatar of arober11
arober11
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of stargateatlantis
stargateatlantis

ASKER

any update on this?
Well, you could ADVERTISE the link as http://www.mydomain.com/authorize/key/1234. If someone clicked on a link that took them to:

  http://www.mydomain.com/authorize/key/1234

... they would be redirected to:

  http://www.mydomain.com/authorize/index.php?key=1234

The distinction here is that mod_rewrite only handles things when someone clicks on a link. It does not rewrite the links on your site for you. It is up to you to create links in the format of http://www.mydomain.com/authorize/key/1234. mod_rewrite will simply convert the request back to the index.php?key=1234 format when someone clicks on it.
The thing is if I go to that link

http://www.mydomain.com/authorize/key/1234 

mod-rewrite should recognize it that that link is in fact this

http://www.mydomain.com/authorize/index.php?key=1234

I shouldn't have to put a dirty link like that in the browser

http://www.mydomain.com/authorize/index.php?key=1234

So if i go to the following link directly

http://www.mydomain.com/authorize/key/1234 

It shouldn't come up with not found it should use this code to re-write it

RewriteEngine On
RewriteBase /
RewriteRule  ^/?authorize/key/([0-9]+)$  /authorize/index.php?key=$1 [L]

Open in new window


But I am not sure if the code above is correct because it isn't working
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Also, mod_rewrite only works when Apache has mod_rewrite loaded and when you have the rewrite rules in a valid place (either in the Apache config, or if you have Overrides enabled, inside a valid .htaccess file)
So would the re-write be this

RewriteEngine On
RewriteBase /
RewriteRule  ^/?authorize/key/(.*)$  /authorize/index.php?key=$1 [L]
                                            

Open in new window

Yes.
None of my comments are selected so not sure why i am getting that error