Hacym Posted September 23, 2012 Share Posted September 23, 2012 (edited) Hello, I am trying to shorten my URLs for a pastebin-like project I am working on. Currently in my htaccess file, I have this: Options +FollowSymlinks RewriteEngine On RewriteRule ^([^/]*)$ /paste.php?pasteid=$1 [NC] I am trying to shorten mydomain.com/paste.php?pasteid=pasteid to just mydomain.com/pasteid. However, with this setup, I am getting an internal server error across the entire domain. I have looked at the logs I have avaliable to me, and cannot find anything referincing this... Any ideas? Edited September 23, 2012 by Hacym Quote Link to comment https://forums.phpfreaks.com/topic/268685-mod_rewrite-issue/ Share on other sites More sharing options...
requinix Posted September 23, 2012 Share Posted September 23, 2012 You've created an infinite loop: paste.php also matches the pattern, thus it'll be rewritten to itself over and over again. Your rewriting should only affect things that don't exist. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)$ /paste.php?pasteid=$1 Note that I changed the * to a + because there must be something there to match against. I also removed the NC because it doesn't change anything. While you're at it, consider making the pattern more specific. Will your "pasteid"s only contain letters and numbers? If you know their exact makeup then you should limit the pattern to only match that. Quote Link to comment https://forums.phpfreaks.com/topic/268685-mod_rewrite-issue/#findComment-1380247 Share on other sites More sharing options...
Hacym Posted September 23, 2012 Author Share Posted September 23, 2012 Thank you! It works! Just one more thing, though. I can still go to the actual link and it doesn't change it. Is there a way to make it do that? Also, yes, the pasteids will only contain letters and numbers. I'm not exactly sure how you would change that though, as I have never done anything like this :X Quote Link to comment https://forums.phpfreaks.com/topic/268685-mod_rewrite-issue/#findComment-1380300 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.