Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:07:16+00:00 2026-06-11T14:07:16+00:00

I posted this on Reddit (r/learnprogramming) and someone there PM’d me and told me

  • 0

I posted this on Reddit (r/learnprogramming) and someone there PM’d me and told me to come here, so here I am!

I have been trying to learn regex’s and I suck at them still. I seriously have difficulty grasping the pattern matching. I am solid in other OOP languages so I figured I would learn regex and it just evades me.

I have downloaded EditPad Pro so I can practice as http://www.regular-expressions.info/tutorial.html suggests. I can get expressions to match bulk text, but I am trying to parse URL’s and I keep missing.

Here is what I am trying to do. I am writing my own permalink .htaccess file as a proof of concept study, so I can hopefully use this is in future sites.

I need to return the following dynamic content from a URL:

I need everything other than http:// http://www.domain.com/ or http:// domain.com/ or domain.com/:

(I am adding a space after http:// because of the limits on new accounts)

http:// http://www.domain.com/asdjh324hj.jpg
http:// http://www.domain.com/asa45s.png
http:// http://www.domain.com/aser24hj.gif/
http:// http://www.domain.com/wer234dsfa/
http:// http://www.domain.com/k3kjk4
http:// http://www.domain.com/k3kasd4/

The matched part will then be appended to:

http:// http://www.domain.com/some_dir/som_subdir/some_file.php?querystring=$1

But, I don’t want any of these urls in the results:

http:// http://www.domain.com/some_dir/some_file.php
http:// http://www.domain.com/some_dir/some_subdir/some_file.html

And I need to prevent hotlinking to images in the image_dir:

http:// http://www.domain.com/image_dir/some_dir/some_subdir/some_image.jpg (or png,gif,etc)

Hotlinked images would be redirected to a page with the passed image as a querystring.

So what RewriteRule regex would I setup to grab this? I understand RewriteRules and the flags, putting matched results into variables, etc, I just can’t figure out what regex I should write to grab the actual result.

If this is too complex for RewriteRules, then please let me know as I am struggling here.

Usually I do these in PHP and would start with:
.com/[a-zA-Z0-9-_.]+
([^/]+)/?$
Then do good ‘ol substrings and checks. It’s hacking it to death and I should be doing better!

I am currently going through the regular-expressions.info tutorials and am making progress, but I keep grabbing the wrong things too.

Thanks for any help you can send my way!

Update: I was able to resolve everything with a ton of help and discussed more here: Mod_Rewrite conditions help for hotlinking but allow local requests

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:07:17+00:00Added an answer on June 11, 2026 at 2:07 pm

    I need everything other than http:// http://www.domain.com/ or http:// domain.com/ or domain.com/:

    RewriteCond %{REQUEST_URI} !^/$
    

    But, I don’t want any of these urls in the results:

    RewriteCond %{REQUEST_URI} !^/some_dir/
    

    The matched part will then be appended to:

    RewriteRule ^(.*)$ /some_dir/som_subdir/some_file.php?querystring=$1 [L]
    

    So in all it should look something like this:

    RewriteCond %{REQUEST_URI} !^/$
    RewriteCond %{REQUEST_URI} !^/some_dir/
    RewriteRule ^(.*)$ /some_dir/som_subdir/some_file.php?querystring=$1 [L]
    

    Which will make it so when you request something like http://www.domain.com/asa45s.html, it will get internally rewritten to some_dir/som_subdir/some_file.php?querystring=asa45s.html. As for the hotlinking bit:

    RewriteCond %{REQUEST_URI} ^/image_dir/
    RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g|bmp|ico)$ [NC]
    RewriteCond %{HTTP_REFERER} !^https?://(www\.)?domain.com/
    RewriteRule ^(.*)$ /some_dir/som_subdir/some_file.php?querystring=$1 [L]
    

    This checks that first the request is for something in the /image_dir/ directory, then that the requested resource ends with a png/gif/jpeg/bmp/ico extension, then that the HTTP referer [sic] does not start with http://www.domain.com/, https://domain.com/ or whatever combination of the 2. If all those are true, then it rewrites the request to the /some_dir/som_subdir/some_file.php file with the original URI as the querystring parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I posted this on the pygame mailing list but maybe someone here will have
I posted this question here before but there were no responses. I may have
I posted this over at reddit but it didn't gain any momentum. So here
I posted this on programmers first , but was told it belongs here. Funny,
Have posted this over at wp.stackex also: Hi I am trying to upload a
I posted this in the IIS forums but there has been no replies. So
I posted this question on Reddit Programming and did not get a single response.
I posted this very same item on SERVERFAULT, but got no reply. So here
I posted this question here on purpose, although - for my case - it
I posted this earlier on wordpress.stackexchange.com. However, never got a reply. Hence, trying my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.