adrianTNT Posted August 3, 2007 Share Posted August 3, 2007 Hello. I have this rule: RewriteRule ^(.*)/ index.php?word=$1 Meaning that site/index.php?word=Adrian is also shown at site/adrian/ But how do I make it work without the slash at end too? site/adrian I thing this should be simple but this is my first attempt with URL rewrite. Thank you. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 3, 2007 Share Posted August 3, 2007 I assume you had your mod_rewrite working as you want it to be, to make it optional, simply just put a ?, so it should be this. RewriteRule ^(.*)/? index.php?word=$1 Quote Link to comment Share on other sites More sharing options...
adrianTNT Posted August 3, 2007 Author Share Posted August 3, 2007 I assume you had your mod_rewrite working as you want it to be, to make it optional, simply just put a ?, so it should be this. RewriteRule ^(.*)/? index.php?word=$1 I tried this just now, It still works with the slash but if I do not enter the slash at end I get: Not Found The requested document was not found on this server. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 4, 2007 Share Posted August 4, 2007 Alright, how about this? RewriteRule ^(.*)(/)? index.php?word=$1 Quote Link to comment Share on other sites More sharing options...
adrianTNT Posted August 4, 2007 Author Share Posted August 4, 2007 Alright, how about this? RewriteRule ^(.*)(/)? index.php?word=$1 That line and many other combinations I try makes it print the file name (index.php) because in index.php I only have echo $_GET['word']; so (that I can see if it works), the line you mentioned shows the right word that I type in url, the one without slash prints "index.php". Maybe the problem is in php/apache settings? But in static site urls (without htaccess) if I do not type the slash it redirects me to the same url with slash at end, it does this by default. Any other ideas? Thank you. Quote Link to comment Share on other sites More sharing options...
adrianTNT Posted August 4, 2007 Author Share Posted August 4, 2007 I think I got it, the problem was that I was trying to rewrite in the same directory, it seems to work ok in other directories. Thanks for your help. - Adrian. 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.