Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

Apache Rewrite does not work as expected

Hi,

I have a site where rewrite does not work as expected.

When accessing the url:

https://secure.website.org/files/download/24/gahik

it does not gets redirected to: https://secure.website.org/files.php?type=download&id=24&unique=gahik

as it should.

Anybody with a good suggestion?

The server er is running:

FreeBSD 8.1
Apache 2.2.17_1
Mysql 5.1.56
PHP 5.2.17

Rewrite module is enabled in httpd.conf.

Thanks.

Regards,
Nikolaj


.htaccess:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^changelang(/)?$ /changelanguage.php

RewriteRule ^login(/)?$ /login.php

RewriteRule ^logout(/)?$ /logout.php

RewriteRule ^files(/)?$ /files.php
RewriteRule ^files/((.*)/(.*)/(.*))? /files.php?type=$2&id=$3&unique=$4
#RewriteRule ^files/(.*)/(.*)/(.*) /files.php?type=$2&id=$3&unique=$4

RewriteRule ^forum(/)?$ /forum.php
RewriteRule ^forum/(.*)/([0-9]{1,})(/(.*))?$ /forum.php?type=$1&id=$2&unique=$4

RewriteRule ^settings(/)?$ /settings.php
RewriteRule ^settings/(.*)/(.*)/([0-9]{1,})$ /settings.php?type=$1&cipher=$2&id=$3

RewriteRule ^user(/)?$ /user.php
RewriteRule ^user/(.*)?$ /user.php?type=$1

RewriteRule ^message(/)?$ /message.php
RewriteRule ^message/(.*)/([0-9]{1,})(/(.*))/((.*))?$ /message.php?type=$1&id=$2&unique=$4&fileunique=$6
RewriteRule ^message/(.*)/([0-9]{1,})(/(.*))?$ /message.php?type=$1&id=$2&unique=$4
RewriteRule ^message/(.*)?$ /message.php?type=$1

Open in new window



site conf file:

<VirtualHost *:443>

    <Directory "/usr/home/wwwhome/secure.website.org/">
        AllowOverride All
        Order allow,deny
        Allow from all
        Options All +Multiviews +FollowSymlinks
    </Directory>

    ServerAdmin info@website.org
    DocumentRoot /usr/home/wwwhome/secure.website.org
    ServerName secure.website.org:443
    ErrorLog /var/log/secure.website.org-error_log
    CustomLog /var/log/secure.website.org-access_log combined

    SSLEngine on
    SSLCertificateFile "/usr/local/openssl/certs/secure.website.org.cert"
    SSLCertificateKeyFile "/usr/local/openssl/certs/secure.website.org.unencrypted.key"
    SSLCACertificateFile "/usr/local/openssl/certs/intermediateca.cert"


</VirtualHost>

Open in new window

0
Nikolaj77
Asked:
Nikolaj77
  • 3
  • 3
1 Solution
 
a1jCommented:
What is your RewriteBase set to?

the URI starts with / so the files will be /files
Since you explicitly matching beginning of the string the ^files patternt will never match /files URI.
Maybe you should try to remove ^ from the pattern or adding / after ^
0
 
Nikolaj77Author Commented:
Hi a1j,

Thanks for your comment.

I have now the following .htaccess:

Options +FollowSymlinks
RewriteEngine on

RewriteBase /

RewriteRule ^changelang(/)?$ /changelanguage.php

RewriteRule ^login(/)?$ /login.php

RewriteRule ^logout(/)?$ /logout.php

RewriteRule files(/)?$ /files.php
RewriteRule files/((.*)/(.*)/(.*))? /files.php?type=$2&id=$3&unique=$4
#RewriteRule ^files/(.*)/(.*)/(.*) /files.php?type=$2&id=$3&unique=$4

RewriteRule ^forum(/)?$ /forum.php
RewriteRule ^forum/(.*)/([0-9]{1,})(/(.*))?$ /forum.php?type=$1&id=$2&unique=$4

RewriteRule ^settings(/)?$ /settings.php
RewriteRule ^settings/(.*)/(.*)/([0-9]{1,})$ /settings.php?type=$1&cipher=$2&id=$3

RewriteRule ^user(/)?$ /user.php
RewriteRule ^user/(.*)?$ /user.php?type=$1

RewriteRule ^message(/)?$ /message.php
RewriteRule ^message/(.*)/([0-9]{1,})(/(.*))/((.*))?$ /message.php?type=$1&id=$2&unique=$4&fileunique=$6
RewriteRule ^message/(.*)/([0-9]{1,})(/(.*))?$ /message.php?type=$1&id=$2&unique=$4
RewriteRule ^message/(.*)?$ /message.php?type=$1

Open in new window



But it still does not work.

Any suggestion?

Thanks.
0
 
Nikolaj77Author Commented:
I got it to work:

Options +FollowSymlinks
RewriteEngine on

RewriteBase /

RewriteRule ^changelang(/)?$ /changelanguage.php

RewriteRule ^login(/)?$ /login.php

RewriteRule ^logout(/)?$ /logout.php

RewriteRule ^files(/)?$ /files.php
RewriteRule ^files\.php/((.*)/(.*)/(.*))? /files.php?type=$2&id=$3&unique=$4
#RewriteRule ^files/(.*)/(.*)/(.*) /files.php?type=$2&id=$3&unique=$4

RewriteRule ^forum(/)?$ /forum.php
RewriteRule ^forum\.php/(.*)/([0-9]{1,})(/(.*))?$ /forum.php?type=$1&id=$2&unique=$4

RewriteRule ^settings(/)?$ /settings.php
RewriteRule ^settings\.php/(.*)/(.*)/([0-9]{1,})$ /settings.php?type=$1&cipher=$2&id=$3

RewriteRule ^user(/)?$ /user.php
RewriteRule ^user\.php/(.*)?$ /user.php?type=$1

RewriteRule ^message(/)?$ /message.php
RewriteRule ^message\.php/(.*)/([0-9]{1,})(/(.*))/((.*))?$ /message.php?type=$1&id=$2&unique=$4&fileunique=$6
RewriteRule ^message\.php/(.*)/([0-9]{1,})(/(.*))?$ /message.php?type=$1&id=$2&unique=$4
RewriteRule ^message\.php/(.*)?$ /message.php?type=$1

Open in new window


Any comments?
0
Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

 
a1jCommented:
Again i dont know what was your rebase set to (dunno what it is by default).
Now that you set it to / all your URI are relative to / thats why your regexps started to work.
0
 
a1jCommented:
rewrite base i meant.
0
 
Nikolaj77Author Commented:
Yes and also added the \.php different places.

Thanks.
0

Featured Post

Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now