Jump to content

Mod_Rewrite Issue


Recommended Posts



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 by Hacym
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.