phpknight Posted August 19, 2007 Share Posted August 19, 2007 I am new to mod_rewrite. Because of cPanel overwriting the httpd.conf file, I have to use .htaccess. It just seems like the rules do not work for me as planned. If somebody can help me figure these first few out, I will probably be able to start making progress. Two examples Example 1 This is a simple version of what I ultimately need to do, but I do not need you to solve it. I just need help getting started. Rule: (.*) getshop.php?shop=$1 What I expect: I think it should work like this: somebody goes to www.myshop.com/bobstore -- it redirects to www.myshop.com/getshop.php? shop=bobstore. So, if I var_dump the $_GET, it should be shop=bobstore. What it does: $_GET dumps shop=getshop.php no matter what goes in place of bobstore. I tried putting NS and some other rules, but nothing helps. It seems to give me the value AFTER the redirect, not before. Example 2 Rule: [:alnum:]* getshop.php What I expect: www.myshop.com/sldk23949 redirects to getshop.php What it does: redirects even www.myshop.com/#($(/1233/*@#*KKdl23 to getshop.php I have tried to use ^ and other things, but nothing behaves as I thought it would. Therefore, if somebody can start me off or even write a simple rule and rewrite that I could try (such as redirecting something with three digits to a certain page), that would be great. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 20, 2007 Share Posted August 20, 2007 I'm not sure what rule you're going to write, so I will just give an example how to use it with $_GET, turning a dynamic url to a static url. Example of dynamic url: http://domain.tld/news.php?articleid=155644 Example of static url: http://domain.tld/article/155644 The rule will look like this, RewriteEngine on RewriteRule ^article/([0-9]+)$ news.php?article=$1 ^ - start of the url ([0-9]+) - the regex, combination of number from 0 to 9 $ - end of the url $1 - just simple means the value from the regex Hope this helps. Quote Link to comment Share on other sites More sharing options...
phpknight Posted August 20, 2007 Author Share Posted August 20, 2007 Okay, I will try that. Can you do that [:alnum:]{4,6} or something? Once I put [:alpha:] or something like that, it stops working. I am thinking I have the syntax wrong. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 20, 2007 Share Posted August 20, 2007 ([[:alnum:]]{4,6}+) Hope this helps. http://us2.php.net/regex is useful. Quote Link to comment Share on other sites More sharing options...
phpknight Posted August 21, 2007 Author Share Posted August 21, 2007 Thanks. It appears because of my version of Apache that I cannot use stuff like [:alnum:]. It just took the whole day to figure that out, lol. Quote Link to comment 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.