Using "P" flag in .htaccess

Hey Folks,

I need to accomplish something using .htaccess that I haven’t done before. I believe it should be accomplished using the “P” flag, and Dreamhost tech support tells me mod_proxy is indeed installed so that should be available.

I just created an example that should make my problem very clear.

When you view it successfully shows you

This was done using this line in my .htaccess file:
RewriteRule example1.html [NC]

So far so good. However, I don’t actually want viewers to see the long version in their navigation bar. I’d like the short .html URL shown in the navigation bar, with the .php?n=… version displayed in the browser. I believe this is what the P flag is meant to accomplish.

And so a second example with the P flag: When you visit it fails to show you

I had put into my .htaccess file:
RewriteRule example2.html [P,NC]

Same as example 1, just added the P flag.
So, why does example 2 fail?

Thanks anybody for your help!

What you’re trying to do does not require the proxy flag. The first example you gave can be implemented as:

Having the domain name in there was forcing this rewrite to generate a browser redirect. Without it, the rewrite can take place internally.

I think mod_proxy is only available on PS and Dedi and it’s not the thing to use when writing “pretty URLs”.

If your post was a bit more than just an example and you actually do have a huge list of exactString# rewrites you can save some typing with this kind of thing:

RewriteEngine On RewriteRule ^example(.*)\.html$ /example.php?n=$1 [NC]

Google mod_rewrite or pretty urls.

You guys rock, thanks so much.

Removing the domain name part of the URL was the key thing. Now, with

RewriteRule example1.html /example.php?n=1 [NC]

it works beautifully. Pretty URL indeed!

Thanks again,

Since you are using PHP anyway, why not just write a dispatcher into your app? Just redirect every request to a single file, such as index.php, and use PHP to parse your requests. It may be easier than htaccess.

If you want to go with the htaccess route, you know you don’t need to create a rule for every page, right? You can use patterns such as:

Above is untested, but will probably work.

Update: Played around with patterns, per bobocat. Now I’m using:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^example([0-9]+)$ /example.php?n=$1 [NC]