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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.