Link to home
Start Free TrialLog in
Avatar of Nikolaj77
Nikolaj77Flag for Denmark

asked on

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

Avatar of a1j
a1j
Flag of United States of America image

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 ^
Avatar of Nikolaj77

ASKER

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.
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?
ASKER CERTIFIED SOLUTION
Avatar of a1j
a1j
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rewrite base i meant.
Yes and also added the \.php different places.

Thanks.