logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: [mod_rewrite] Overwrite parent's htaccess rewrite rule
Author
benny00100



Joined: 05 Feb 2015
Posts: 3

PostPosted: Thu 05 Feb '15 14:40    Post subject: [mod_rewrite] Overwrite parent's htaccess rewrite rule Reply with quote

Hi,

I have got a problem with mod_rewrite and looking for help.

Current situation:

The main project is directly located in the projectroot folder. A subproject lies in a subfolder of the main project.

/projectroot/.htaccess
/projectroot/*.php (various PHP files of the main project)

/projectroot/subproject/.htaccess
/projectroot/subproject/* (various files incl. PHP files)

In the subproject I have the following .htaccess rule, which redirects requests to files which doesn't exists to the 404.php script.

# Redirect von ungültigen URL request auf 404.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ 404.php [L]


The problem:

In the parent dir of the main project the .htaccess contains the following rule

<FilesMatch "\.(htm|php|js|css|htc|png|gif|jpe?g|ico|xml|csv|txt|swf|flv|mp4|webm|ogv|mp3|ogg|oga|eot|woff|svg|ttf|pdf|gz)$">
RewriteEngine Off
</FilesMatch>

This causes, that in my subproject - all requests to non-existing php files do not redirect to 404.php

So:

/projectroot/subproject/doesnotexists redirects to 404.php

whereas

/projectroot/subproject/doesnotexists.php does not work


The question:

Is there a way to overwrite the parents' .htaccess rule. I tried the following without any luck:

<FilesMatch "\.(php)$">
RewriteEngine On
</FilesMatch>

Thanks for help.

Best,
benny!
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Fri 06 Feb '15 4:59    Post subject: Reply with quote

To be honest, this seems like a very expensive way to have a custom 404 page. I do not think mod_rewrite was ever designed for this purpose, this is what ErrorDocument is for.

Likewise, unless you have turned on RewriteEngine above /projectroot, RewriteEngine is off by default.
Back to top
benny00100



Joined: 05 Feb 2015
Posts: 3

PostPosted: Sat 07 Feb '15 9:27    Post subject: Reply with quote

Thanks for your reply.

Hmm ... About the 404 case you might be right - but this is not the issue.

If it makes more sense, replace the 404.php with maincontroller.php Wink Like most PHP MVC frameworks are using mod_rewrite.

So, I really wonder how this "overwriting" of parents htaccess rules can work. Question
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sat 07 Feb '15 20:01    Post subject: Reply with quote

OK, I guess I should have simply asked.

1. What does happen when you go to /projectroot/subproject/doesnotexists.php? "Does not work" doesn't tell anyone anything useful. It probably actually works as it should it's just not what you THINK should happen.

2. Why on earth do you have this in the parent folder?
<FilesMatch "\.(htm|php|js|css|htc|png|gif|jpe?g|ico|xml|csv|txt|swf|flv|mp4|webm|ogv|mp3|ogg|oga|eot|woff|svg|ttf|pdf|gz)$">
RewriteEngine Off
</FilesMatch>

Yes, most frameworks use rewriting for fancy URLs, also known as search engine friendly URLs.

So, where is this framework needing rewriting for fancy urls. Parent folder (projectroot), subfolder (subproject), both?
Back to top
benny00100



Joined: 05 Feb 2015
Posts: 3

PostPosted: Fri 13 Feb '15 10:51    Post subject: Reply with quote

Hey glsmith - sorry for belated answer.

glsmith wrote:
...
1. What does happen when you go to /projectroot/subproject/doesnotexists.php? "Does not work" doesn't tell anyone anything useful. It probably actually works as it should it's just not what you THINK should happen.
...


Apache returns a standard 404.

glsmith wrote:

2. Why on earth do you have this in the parent folder?
<FilesMatch "\.(htm|php|js|css|htc|png|gif|jpe?g|ico|xml|csv|txt|swf|flv|mp4|webm|ogv|mp3|ogg|oga|eot|woff|svg|ttf|pdf|gz)$">
RewriteEngine Off
</FilesMatch>
...


Unfortunately, everything in the parent folder incl. the htaccess is not in my scope. So, I cannot make any modifications in there.
No idea, what this is for?

glsmith wrote:

So, where is this framework needing rewriting for fancy urls. Parent folder (projectroot), subfolder (subproject), both?


Only in the subfolder. I don't want to / cannot do any changes in the projectroot folder?

Thanks for your help!

Best,
benny!
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sat 14 Feb '15 21:10    Post subject: Reply with quote

benny00100 wrote:
glsmith wrote:
...
1. What does happen when you go to /projectroot/subproject/doesnotexists.php? "Does not work" doesn't tell anyone anything useful. It probably actually works as it should it's just not what you THINK should happen.

Apache returns a standard 404.

Fine, if it returns the standard ugly white 404 page then just use;

ErrorDocument 404 /uri/to/whatever-you-want.php
Back to top


Reply to topic   Topic: [mod_rewrite] Overwrite parent's htaccess rewrite rule View previous topic :: View next topic
Post new topic   Forum Index -> Apache