Jump to content

Basic rewrite woes


Drongo_III

Recommended Posts

Hi Guys

 

I wonder if someone can help. 

 

I need to rewrite a url that so a pretty url such as /card/somedir/somepage?id=345 will rewrite to the real script page with queries strings

 

I have been trying the following to no avail:

RewriteEngine On
RewriteRule ^/card/somepage/otherpage/ http://www.mysite.com/card/default.php [QSA]

I really need to bone up on this stuff because I find from one server to the next things seem a bit inconsistent. But anyway if anyone could point out where I am going wrong it would be appreciated.

 

Drongo

Link to comment
https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/
Share on other sites

Dont use absolute http urls for the replacement url. This will cause a redirect. Just provide the path to the file the rewrite rule should perform the request to

RewriteEngine On
RewriteRule ^/card/somepage/otherpage/ default.php [QSA]

 The url site.com/card/somepage/otherpage/ and site.com/card/somepage/otherpage/?id=345 should call default.php. To get the id from the query string use the $_GET['id'] superglobal variable

Link to comment
https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/#findComment-1455139
Share on other sites

Dont use absolute http urls for the replacement url. This will cause a redirect. Just provide the path to the file the rewrite rule should perform the request to

RewriteEngine On
RewriteRule ^/card/somepage/otherpage/ default.php [QSA]

 The url site.com/card/somepage/otherpage/ and site.com/card/somepage/otherpage/?id=345 should call default.php. To get the id from the query string use the $_GET['id'] superglobal variable

 

 

Unfortunately this doesn't appear to work.

 

I just get:

 

The requested URL /card/somepage/otherpage/ was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

 

I assume the apach isn;t finding a match.  Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/#findComment-1455141
Share on other sites

Try the following rewrite rule

RewriteRule ^card/somepage/otherpage/ default.php [QSA]

default.php should be in your sites root folder

 

 

The default.php file is in the card directory. So I tried

RewriteEngine On

RewriteRule ^card/somepage/otherpage/ /card/default.php [QSA]

If I do this as a straight redirectMatch it works fine but I don't think the query string is presreved in that instance.

Link to comment
https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/#findComment-1455147
Share on other sites

The default.php file is in the card directory.

Oh, didn't realise default.php was in card directory. 

 

 

If I do this as a straight redirectMatch it works fine but I don't think the query string is presreved in that instance.

Yes that should still work with either site.com/card/somepage/otherpage/ and site.com/card/somepage/otherpage/?id=345

 

Have you tried it?

Link to comment
https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/#findComment-1455149
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.