Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: rewriterule can't make it work  (Read 166 times)

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
rewriterule can't make it work
« on: March 15, 2013, 09:27:03 AM »

Hi there

I have this link
http:// 127.0.0.1/snews17/dl.php?f=file1.pdf

I try to make it appear like this
http:// 127.0.0.1/snews17/files/file1.pdf

but I have no luck so far
here is some rewriterules that I have try

Quote
RewriteEngine On
#RewriteBase /sNews17
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?category=$1 [L]

#RewriteRule ^files/([0-9]+)/?$ dl.php?f=$1 [NC,L]
#RewriteRule ^files/(.*)$ dl.php?f=$1.pdf [NC,L]
#RewriteRule ^files/([0-9]+)-([a-z]+) /dl.php?f=$1.pdf [NC]
RewriteRule ^files/([A-Za-z0-9-]+)/?$ dl.php?f=$1 [NC,L]

Any idea about?
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: rewriterule can't make it work
« Reply #1 on: March 15, 2013, 10:39:01 AM »

If you are using this with sNews, you may need to add "files" to the SEF catlist, then do the processing. I don' think you need to work with rewrite.
Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: rewriterule can't make it work
« Reply #2 on: March 15, 2013, 11:22:27 AM »

Hmm I lost you here!!

I follow this rewrite rule
RewriteRule ^files/([^/]+).pdf dl.php?f=$1 [NC]

where I take it from
http://corz.org/serv/tricks/htaccess2.php#section-short_URLs
the above is wrong url
http://corz.org/serv/tricks/htaccess2.php#section-not_so_simple

Nothing so far and I am not sure if is possible to make this rewrite
the link is manual generated i.e.

Quote
foreach($files_array as $key=>$val){
echo '<li><a href="dl.php?f='.urlencode($val).'">'.$val.'

perhaps to make it work is to return the dl.php?f= from some function?

« Last Edit: March 15, 2013, 02:33:00 PM by sibas »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: rewriterule can't make it work
« Reply #3 on: March 15, 2013, 03:37:08 PM »

I may be completely wrong but

a) I don't think returning "dl.php?f=" from some function will make a difference, and
b) The link is (I think) treated by sNews the same as any other link, so
RewriteRule ^files/([^/]+).pdf dl.php?f=$1 [NC]
won't work - i.e is (probably) cancelled by the
RewriteRule ^(.*)$ index.php?category=$1 [L] line.

How to solve it? Woush, I have no idea. Sorry.
Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: rewriterule can't make it work
« Reply #4 on: March 15, 2013, 03:43:31 PM »

Hi Fred you are right is not possible the above not only for the reason you say..

what I was try to do is to change the link
<a href="http:// 127.0.0.1/snews17/dl.php?f=file1.pdf>file1.pdf</a>
in to
<a href="http:// 127.0.0.1/snews17/files/file1.pdf>file1.pdf</a>

my mistake

But if I have this link
<a href="http:// 127.0.0.1/snews17/files/file1.pdf>file1.pdf</a>

and make rewriterule to catch the word "files" and return dl.php?f=
I think maybe is going to work..
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: rewriterule can't make it work
« Reply #5 on: March 15, 2013, 08:10:06 PM »

I can't understand why you'd want to get into having to write a rule to conver a link to a static PDF file.
All you need to do is upload the file to your host server's domain root (or a folder in it) and make the link to it.
It's also important to make sure the file-name has no spaces between words in it. I've experienced a lot of problems with clients uploading files with improper file-name structure and not being able to link to or - even - find them because the server sees them as being corrupt files.

If you have a file named file1.pdf and you upload it to your domain root, the link to it would be:
http://domainname.com/file1.pdf
If you uploaded it to a folder in your domain root called pdf, the link to it would be:
http://domainname.com/pdf/file1.pdf

It can't get any simpler than that.  8)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: rewriterule can't make it work
« Reply #6 on: March 16, 2013, 11:13:55 AM »

unfortunately for some files must count the downloads, thats why I have to use the dl.php
now, when it comes to allow users download from some script you need some security,
making a simple rewriting hides the script name from some scriptkids and looks a better link.
Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: rewriterule can't make it work
« Reply #7 on: March 16, 2013, 12:10:18 PM »

Well I found this link where explains exactly what I have to do,
http://wiki.apache.org/httpd/RewritePathInfo
read the Moving path information to a query string
the simplest possible rule is
RewriteRule ^/files/([^/]*) /dl.php?f=$1 [PT]
but no luck, link http ://127.0.0.1/snews17/files/Newsletter1.pdf leads to 404
does not execute the script
any idea?
Logged