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

Nikolaj77Asked:
Who is Participating?
 
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:
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
Live Q & A: Securing Your Wi-Fi for Summer Travel

Traveling this summer? Join us on June 18, 2018 for a live stream to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

 
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
 
a1jCommented:
rewrite base i meant.
0
 
Nikolaj77Author Commented:
Yes and also added the \.php different places.

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.