+ Reply to Thread
Results 1 to 8 of 8

Thread: .htaccess acting up

  1. #1
    espfutbol98's Avatar
    espfutbol98 is offline x10 Sophmore espfutbol98 is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Zagreb... želim
    Posts
    200

    Question .htaccess acting up

    I have had some url rewriting problems but I usually just worked around them. The overall problem is basically, a rewritten url that is similar to another is redirected. And example is terror.audio. I redirected all .audio files to a special folder that holds mp3s. For some reason, it likes to put the /error page in the place of just terror.audio. Here is my root .htaccess file:
    Code:
    Redirect /bank /~mason/bank
    order allow,deny
    deny from 66.249.*.*
    deny from 220.162.207.62
    deny from 38.119.107.*
    deny from 207.44.237.18
    deny from 82.192.79.7
    deny from 74.125.75.1
    deny from 218.64.91.94
    allow from all
    Options -Indexes
    ErrorDocument 400 /error?400
    ErrorDocument 401 /error?401
    ErrorDocument 403 /error?403 
    ErrorDocument 404 /error?404 
    ErrorDocument 500 /error?500
    SetEnv TZ Europe/Berlin
    AddDefaultCharset UTF-8
    DefaultLanguage hr-HR
    DirectoryIndex index.php naslovnica.php index.html
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index.php$ naslovnica.php
    RewriteRule ^login$ login.php
    RewriteRule ^logout$ logout.php
    RewriteRule ^naslovnica$ naslovnica.php
    RewriteRule ^glazba$ glazba.php
    RewriteRule ^guest$ guest.php
    RewriteRule ^o_nama o_nama.php
    RewriteRule ^kontakt kontakt.php
    RewriteRule ^druge_stranice druge_stranice.php
    RewriteRule ^projekti projekti.php
    RewriteRule ^glazba glazba.php
    ReWriteRule ^masta_ace masta_ace.php
    RewriteRule ^mos_def mos_def.php
    RewriteRule ^common common.php
    RewriteRule ^jezik jezik.php
    RewriteRule ^preuzimanja preuzimanja.php
    RewriteRule ^druga_preuzimanja druga_preuzimanja.php
    RewriteRule ^brisanje_račun delete_account.php
    RewriteRule ^register register.php
    RewriteRule ^izmjena_računu update_account.php
    RewriteRule ^samo_korisnike samo_korisnike.php
    RewriteRule ^moj_račun user_personal.php
    RewriteRule ^moj_racun user_personal.php
    RewriteRule ^kutak_za_korisnike kutak_za_korisnike.php
    RewriteRule ^signup signup.php
    RewriteRule ^linkovi linkovi.php
    RewriteRule ^mc_sniper mc_sniper.php
    RewriteRule ^other_music$ other_music.php
    RewriteRule ^hrvatski hrvatski.php
    RewriteRule ^korejski korejski.php
    RewriteRule ^([^/]+).pdf /design/documents/$1.pdf 
    RewriteRule ^([^/]+).zip /design/documents/$1.zip 
    RewriteRule ^([^/]+).audio$ https://podaci.co.uk/design/audio/$1.mp3 
    RewriteRule ^([^/]+).wma$ https://podaci.co.uk/design/audio/$1.wma 
    RewriteRule ^([^/]+).mp3$ https://podaci.co.uk/design/audio/$1.mp3 
    RewriteRule ^([^/]+).png /design/images/$1.png 
    RewriteRule ^([^/]+).glazba$ https://podaci.co.uk/design/audio/mc_sniper/$1.mp3 
    RewriteRule ^([^/]+).jpg /design/images/$1.jpg
    RewriteRule ^ssl$ ssl.php
    RewriteRule error error.php
    RewriteRule ^hr$ lang.php?hr
    RewriteRule ^en$ lang.php?en
    RewriteRule ^~([^/]+)$ /users/$1/
    RewriteRule ^~([^/]+)(.*)$ /users/$1$2
    ##################Login#################################
    RewriteRule ^([^/\.]+)/logout$ logout.php?redirect=$1
    RewriteRule ^([^/\.]+)/([^/\.]+)/logout$ logout.php?redirect=$1&name=$2
    RewriteRule ^([^/\.]+)/login$ login.php?redirect=$1
    RewriteRule ^([^/\.]+)/([^/\.]+)/login$ login.php?redirect=$1&name=$2
    ########################################################
    How should I solve this? I have read, what I believe to be, all the documentation on the Apache website and have found nothing.

    By the way, if you want to see how it fails, https://podaci.co.uk/terror.audio?403 shows the error?403 page when it should be (without the ?403 of coarse) an mp3.

    Even the actual location (https://podaci.co.uk/design/audio/terror.mp3) with the ?403 gives the 403 error page. And without the ?403 the blank error page.
    Last edited by espfutbol98; 09-24-2009 at 12:26 AM.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: .htaccess acting up

    "terror.audio" and "design/audio/terror.mp3" match "error", so the "RewriteRule error error.php" line takes effect. Rather than fixing just that one line, you can replace that line and all the lines that add ".php" extensions with the following:
    Code:
    RewriteCond %(DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^/?(.*)$    $1.php
    RewriteRule ^/?error\.php - [L]
    (Overall, you could make better use of regular expressions.) The first two lines append a ".php" if doing so names a file that exists. The third is an optimization to stop rewriting the error page URL.

    An alternative is to turn on content negotiation (my personal preference) by adding "Options +MultiViews". With content negotiation, Apache will automatically add file extensions to URLs.

    You should add the "last" flag ([L]) to every RewriteRule that doesn't need further processing. That way, you won't accidentally rewrite a URL in a later rule. This would also have prevented the problem with the "error" rewrite.

    Another thing that might cause other problems is that "." matches any single character, so the ".audio" subpattern will match "/audio". If you want to match a literal period, escape the dot and use "\.". Note that the dot isn't special in character classes, so you don't need to escape it there ("[.]" will match a literal period and nothing else).

    You probably don't need the "RewriteBase /". Why do you have it?

    Applying all the above suggestions (and a few more fixes), you get:
    Code:
    RewriteEngine on
    
    # force secure connection for audio files
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?([^/]+\.(audio|mp3|wma|glazba))$ https://podaci.co.uk/$1 [L]
    
    RewriteRule ^/?([^/]+)\.(pdf|zip)$ /design/documents/$1.$2 [L]
    RewriteRule ^/?([^/]+)\.(png|jpg|gif)$ /design/images/$1.$2 [L]
    RewriteRule ^/?([^/]+)\.(audio|mp3)$ /design/audio/$1.mp3 [L]
    RewriteRule ^/?([^/]+)\.wma$ /design/audio/$1.wma [L]
    RewriteRule ^/?([^/]+)\.glazba$ /design/audio/mc_sniper/$1.mp3 [L]
    
    RewriteRule ^/?index(\.php|$) naslovnica.php
    RewriteRule ^/?moj_račun(\.php|$) user_personal.php
    
    #alternative to the following two lines: Options +MultiViews
    RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^/?(.*)$    $1.php
    RewriteRule ^/?error\.php - [L]
    
    RewriteRule ^(hr|en)$ lang.php?$1
    RewriteRule ^~([^/]+)$ /users/$1/
    RewriteRule ^~([^/]+)(.*) /users/$1$2
    
    ##################Login#################################
    RewriteRule ^([^/.]+)/log(in|out)$ log$2.php?redirect=$1 [L]
    RewriteRule ^([^/.]+)/([^/\.]+)/log(out|in)$ log$3.php?redirect=$1&name=$2 [L]
    ########################################################
    Last edited by misson; 09-24-2009 at 08:03 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    espfutbol98's Avatar
    espfutbol98 is offline x10 Sophmore espfutbol98 is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Zagreb... želim
    Posts
    200

    Re: .htaccess acting up

    WOW! Thank you very much!

    By the way, I'm not sure why I have the RewriteBase /. I guess I just found it with an online example of something else and didn't get rid of it for a lack of understanding what it is.

    Some things I have found:
    RewriteCond %(DOCUMENT_ROOT}/$1.php -f I think should be RewriteCond %{DOCUMENT_ROOT}/$1.php -f

    With the audio files, I had to make a full url (ie https://podaci.co.uk) or else on the download page, it would be song.glazba.
    Last edited by espfutbol98; 09-24-2009 at 05:46 PM.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: .htaccess acting up

    Quote Originally Posted by espfutbol98 View Post
    Some things I have found:
    RewriteCond %(DOCUMENT_ROOT}/$1.php -f I think should be RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    Yeah, that's a typo. It's fixed now. In addition, I didn't give a rule that would rewrite "moj_račun" to "user_personal.php", which is also now fixed.

    Quote Originally Posted by espfutbol98 View Post
    With the audio files, I had to make a full url (ie https://podaci.co.uk) or else on the download page, it would be song.glazba.
    Ah, you mean you want the URL in the browser to reflect the true path. Do you want to allow non-secure access to the audio files? If so, you can just use a redirect flag. Replace the rewrite rules for audio files with:
    Code:
    RewriteRule ^/?([^/]+).(audio|mp3)$ /design/audio/$1.mp3 [R=301,L]
    RewriteRule ^/?([^/]+).wma$ /rewrite/design/audio/$1.wma [R=301,L]
    RewriteRule ^/?([^/]+).glazba$ /rewrite/design/audio/mc_sniper/$1.mp3 [R=301,L]
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    espfutbol98's Avatar
    espfutbol98 is offline x10 Sophmore espfutbol98 is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Zagreb... želim
    Posts
    200

    Re: .htaccess acting up

    Quote Originally Posted by misson View Post
    In addition, I didn't give a rule that would rewrite "moj_račun" to "user_personal.php", which is also now fixed.
    I just decided to rename the actual php files to reflect the .htaccess rules. I think it is a better system and is easier when editing files.

    Thanks again for all the help!

  6. #6
    vlatkomk is offline x10Hosting Member vlatkomk is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    11

    Re: .htaccess acting up

    I want to restrict a page where someone comes from abroad to show another page and when the national network to the actual page opens.
    I'm not familiar so much for help.
    Thank you

  7. #7
    ichwar's Avatar
    ichwar is offline Community Advocate ichwar is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    NC, USA
    Posts
    1,454

    Re: .htaccess acting up

    Quote Originally Posted by vlatkomk View Post
    I want to restrict a page where someone comes from abroad to show another page and when the national network to the actual page opens.
    I'm not familiar so much for help.
    Thank you
    vlatkmok, please don't ask for help for your problem in someone else's thread. It's likely that you'll wait quite a while before someone finds your post. You're better off creating a new thread in http://forums.x10hosting.com/programming-help/

  8. #8
    vlatkomk is offline x10Hosting Member vlatkomk is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    11

    Re: .htaccess acting up


+ Reply to Thread

Similar Threads

  1. .htaccess Problem!
    By cookie22 in forum Free Hosting
    Replies: 3
    Last Post: 04-18-2009, 12:12 PM
  2. Se puede usar .htaccess????
    By rackfenix in forum Soporte
    Replies: 7
    Last Post: 10-02-2007, 07:03 PM
  3. default .htaccess
    By Fedlerner in forum Computers & Technology
    Replies: 9
    Last Post: 09-05-2007, 09:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers