Jump to content

Mod_Rewrite Issue


Hacym

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/268685-mod_rewrite-issue/
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
https://forums.phpfreaks.com/topic/268685-mod_rewrite-issue/#findComment-1380247
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
https://forums.phpfreaks.com/topic/268685-mod_rewrite-issue/#findComment-1380300
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.