1

I just spent the last 10 hours of my life on this & am running in circles, so was hoping someone may be able to help me.

I want a specific URL to load like this:

http://example.com/f/2011/image.png?attribute=small

When a URL in a format such as this hits, I'd like to rewrite it to hit the server as:

http://example.com/generate.php?f=2011/image.png&attribute=small

Based on above, my question is two-fold:

  1. How can I rewrite the URL in htaccess to meet my requirements above?
  2. If the original URL didn't have the attribute query string parameter, how can I ensure attribute will be false/blank/etc when it hits the server via htaccess?

3 Answers 3

2
RewriteEngine On # If it's not an existing file... RewriteCond %{REQUEST_FILENAME} !-f # ...and it's not an existing directory... RewriteCond %{REQUEST_FILENAME} !-d # ...and it starts with "f/" then rewrite it to generate.php RewriteRule ^f/(.*)$ generate.php?f=$1 [L,QSA] 

The two RewriteCond can be omitted. More information:

RewriteRule

QSA flag

0
1
RewriteEngine On RewriteRule ^([a-z]+)/([0-9]+)/image.png?attribute=small$ generate.php?f=$2/image.png&attribute=small&%{QUERY_STRING} [L] 
0

Here's one that have more chances to work:

RewriteEngine On # If it's not an existing file... RewriteCond %{REQUEST_FILENAME} !-f # ...and it's not an existing directory... RewriteCond %{REQUEST_FILENAME} !-d # ...and it starts with "f/" then rewrite it to generate.php RewriteRule ^([a-z]+)/([0-9]+)/image\.png$ /generate.php?f=$1 [QSA,L] 

Please tell me if it works

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.