Rewrite rule to change php to html in subdirectory

Hello Forums,

I needed to change 2 files in a subdirectory from .php to .html so an android APP can access it. Here’s what I have so far


RewriteEngine on
RewriteRule ^event_upload.html?$  /mobile/event_upload.php [NC,L]

event_upload.php is in an actual directory named mobile and I need to change it to event_upload.html

Thanks,

Why the question mark?

try it without:


RewriteEngine on
RewriteRule ^event_upload.html$  /mobile/event_upload.php [NC,L]

Hello still does not work

Here is my full htaccess at the root folder

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^event_upload.html$  /mobile/event_upload.php [NC,L]
</IfModule>

BOTH,

The original? simply made the L optional.

sd,

OMG! That draws a standard rant:

[standard rant #4][indent]The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> … </IfModule> wrapper is the same thing in the webmaster world. DON’T BE AN IDIOT! If you don’t know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache’s resources (and should NEVER be allowed on a shared server).[/indent][/standard rant #4]

Okay, take heed and please don’t abuse your server with <IfModule> wrappers. They’re only there to protect the canned app developers from whiners who have no clue what there server is capable of.

RewriteEngine on
RewriteRule ^event_upload.html$  /mobile/event_upload.php [NC,L]

From that I can see that you’re on an Apache 2.x server (no leading / after the start anchor), that you don’t know to escape the dot character in regex, that you’re redirecting to mobile/event_uupload.php and have no clue what the No Case flag is used for. I would have used:

RewriteEngine on
RewriteRule ^event_upload[SIZE=4]\\[/SIZE].html$  [COLOR="#FF0000"]/[/COLOR]mobile/event_upload.php [R=301,L] 
# for testing, the R=301 will display the redirection for you. In the operational world,
# it would tell SE's to change their database to contain the new link, not the old.
# IF you're satisfied that it works and want to hide the redirection, simply remove the R=301, from the flags.
RewriteRule ^event_upload\\.html$  mobile/event_upload.php [L]

Question: Your statement “event_upload.php is in an actual directory named mobile and I need to change it to event_upload.html” is not represented in this code. What are you trying to do, change event_upload.html to event_upload.php but serve mobile/event_upload.php? If so, you’ll need to simply change the file extension with an R=301 (so event.php is seen) then use another RewriteRule to add the mobile/ subdirectory with a simple Last flag.

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

Regards,

DK

Thanks DK escaping periods worked …and yah I removed the ifmodule wrapper …silly me

stoney,

Great to know you’ve resolved your problem. Don’t worry, not silly - I didn’t know about the <IfModule> wrapper as a mod_rewrite newbie either!

Regards,

DK