Drongo_III Posted October 23, 2013 Share Posted October 23, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/ Share on other sites More sharing options...
Ch0cu3r Posted October 23, 2013 Share Posted October 23, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/#findComment-1455139 Share on other sites More sharing options...
Drongo_III Posted October 23, 2013 Author Share Posted October 23, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/#findComment-1455141 Share on other sites More sharing options...
Ch0cu3r Posted October 23, 2013 Share Posted October 23, 2013 (edited) Try the following rewrite rule RewriteRule ^card/somepage/otherpage/ default.php [QSA] default.php should be in your sites root folder Edited October 23, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/#findComment-1455144 Share on other sites More sharing options...
Drongo_III Posted October 23, 2013 Author Share Posted October 23, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/#findComment-1455147 Share on other sites More sharing options...
Ch0cu3r Posted October 23, 2013 Share Posted October 23, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/283217-basic-rewrite-woes/#findComment-1455149 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.