Forum Moderators: phranque

Message Too Old, No Replies

Query in .htaccess: Is mod_rewrite possible in current dir

Check for mod_rewrite before trying to apply conditions

         

cyberskater

1:55 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



The Problem:

Using a software which requieres a rewrite condition, but the application is copied between differnt servers and you never now directly "does the linux server support rewriting?". When rewriting is possible it should use it, otherwise it will use a fallback condition.

I tried a lot, but could not find any solution for the problem, that's why i'm ot going to put any tries here.

Here is what is requiered, but i have no idea how to manage this:


<test for mod_rewrite is possible>
<if requested directory does not contains files or images or,....>
<if request does not contain ^(.*).php?page(.*)$>
Redirect all requests to /index.php?key={everything after "domain.tld/" in the request}
<if request does not contain ^(.*).php?page(.*)$>
</if requested directory does not contains files or images or,....>
</test for mod_rewrite is possible>

Damian

12:59 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



Welcome to Webmasterworld cyberskater.

Maybe you could parse the httpd.conf file?
If there is a line somewhat like the one below in it I guess it is safe to say the server supports rewriting.

LoadModule rewrite_module /the/path/to/apache/mod_rewrite.so

Alternatively maybe you could check for the presence of the 'mod_rewrite.so' file on the system?

There may be better methods, the above is just what came to my mind first.

cyberskater

2:30 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



Sorry, maybe you did not get the point :-)

I ment that I will not have access to the httpd.conf.

The reason why I need an .htaccess file with this configuration is, that I don't want to check for beeing able to use rewriting. I just want to use rewriting if I am allowed to use it on the single server.

When I go and install a piece of software on target server X, there should be no reason to contact the system administrator and ask him for rewriting is allowed for the webspace the software is uploaded to. The software will automaticaly configure itself, when the website is hit by a client browser for the first time.

The purpose is:
Use rewriting if possible, otherwise don't.

So the question is, is it possible to query inside a .htaccess file, whether this webspace is allowed to use rewriting and if yes how this code would look like?

Thanks :-)

Damian

2:58 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



Maybe this helps:
I think in both httpd.conf and .htaccess you could write something like

<IfModule mod_rewrite.c>
# do something
</IfModule>

[httpd.apache.org...]

cyberskater

3:28 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



But I always thought, this only checks whether this module is installed? I need to check whether i am allowed to use rewriting at all.

Or does this query result in just that?

Damian

4:29 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



>But I always thought, this only checks whether this module is installed?
Did you follow the link and read the documentation as well?
If I understand your problem properly now it describes what you need.


The <IfModule test>...</IfModule> section is used to mark directives that are conditional. The directives within an IfModule section are only processed if the test is true. If test is false, everything between the start and end markers is ignored.

>I need to check whether i am allowed to use rewriting at all.
I have a hard time thinking of another reason why mod_rewrite would be installed. I guess that if .htaccess overrides are not allowed in the folder where you work it wouldn't work there, but then it wouldn't make sense to have an .htaccess file there in the first place afaik.

cyberskater

5:00 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



Well ok, I'll play arround a little more.
I'll post the final result, when I am through to show you what i mean :-)