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. Link to comment https://forums.phpfreaks.com/topic/63129-making-this-same-rewrite-rule-work-without-the-slash-at-end-of-url/ 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 Link to comment https://forums.phpfreaks.com/topic/63129-making-this-same-rewrite-rule-work-without-the-slash-at-end-of-url/#findComment-315016 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. Link to comment https://forums.phpfreaks.com/topic/63129-making-this-same-rewrite-rule-work-without-the-slash-at-end-of-url/#findComment-315066 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 Link to comment https://forums.phpfreaks.com/topic/63129-making-this-same-rewrite-rule-work-without-the-slash-at-end-of-url/#findComment-315428 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. Link to comment https://forums.phpfreaks.com/topic/63129-making-this-same-rewrite-rule-work-without-the-slash-at-end-of-url/#findComment-315437 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. Link to comment https://forums.phpfreaks.com/topic/63129-making-this-same-rewrite-rule-work-without-the-slash-at-end-of-url/#findComment-315463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.