Programmatic redirection

software development

#1

I currently have a hosting account with dreamhost. How do I do automatic redirection of something like this?

www.mysite.com/1234 -> www.mysite.com/subdir/page.html?param1=1234

currently i’ve done this: created a folder called “1234” under root, added index.php there which does 302 redirection. However I have to do it for every parameter and it’s not scalable. I would like to make it automatic for any parameter. How do I do so?


#2

If you’re trying to avoid the redirection, then you want to rewrite the URL instead.

Here is the relevant documentation:

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Customer since 2000 :cool: openvein.org | Please don’t feed the trolls. :@


#3

Use .htaccess rewrites:

Options +FollowSymlinks RewriteEngine on RewriteRule ^/([0-9]+) http://mysite.com/subdir/page.html?param1=$1 [NC] That should var the number and insert it at $1.

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#4

I tried that but doesn’t seem to work. Currently I’m trying it inside a subfolder called “Try” for validation.

First, I enabled .htaccess/WebDav for “Try” folder inside dreamhost web control panel. Then I put .htaccess file there with this content

Options +FollowSymlinks
RewriteEngine on
RewriteRule /Try/1033 http://mysite.com/subdir/page.html [NC]

Notice i’m not using regex params yet for simplicity. But looks like the whole rewrite thing isn’t working for me. What am I missing? I get HTTP 404 not found when I access mysite.com/Try/1033


#5

Maximum Cash Discount on any plan with [url=http://www.dreamhost.com/r.cgi?384814/signup|MAXCASH]MAXCASH[/url]

[url=http://sxi.sabrextreme.com]How To Install PHP.INI / ionCube on DreamHost[/url]

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#6

Tried that too. Still no luck.

To reconfirm, I’ve turned on mydomain.com/Try folder for .htaccess. In dreamhost panel, it shows up with “Link Protection” on and “Password Protection”/“WebDAV” off. Should I try to configure it any other way?


#7

You don’t need to turn anything “on” to use .htaccess files with DreamHost. Perhaps the best thing to do is undo any “One-Click rules” and add them manually. While you can place .htaccess files anywhere, it’s good practice to keep rewrite directives within the domain root .htaccess file.

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#8

Still no luck. However I would like to confirm a few things about placement of .htaccess files.

First, I’ve “Link Protection” turned on because dreamhost requires me to have at least one of the options to be on to enable .htaccess.

Second, I’ve put .htaccess file directly inside the “Try” folder. Also I’ve enabled “Try” for .htaccess.

If I move .htaccess to root, do I need to enable .htaccess for root folder as well?
Also, which root? ftp root OR www root?

Thanks.


#9

“www root” - it’s usually a directory named something like domain.com in a userspace. eg. /home/username/domain.com/

I’m at a total loss with every “requirement” you just mentioned :frowning:

Is this some new Private Server setup with the crowd they recently bought into or something?

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#10

This is not a private server. I have signed up for regular plan which shares the server by default. I’ve shared screenshot of my dreamhost htaccess config panel at this location:

http://cid-816809c4d8505697.skydrive.live.com/self.aspx/.Public/htaccess-config.JPG

As you see, there are three checkboxes. If I leave all three unchecked, dreamhost gives me error saying I need to check at least one of them. Let me know which one should I check.

Also as per your suggestion, if I move .htaccess to my www root (achlon.com folder inside my ftp folder), do I also need to enable .htaccess on that folder?

Thanks.


#11

Ahhhh - WebDAV!

You should notice the warning when you click into that section:

Do not enable this for directories which are intended to be viewed with a web browser.

Disable it. Kill it with fire. Forget about why it says “htaccess”. Just know that htaccess works without it.

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#12

If the admins see this thread, it might be a good idea to bold that bit in Panel (like advanced stuff is highlighted in the Wiki).

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#13

Done! :smiley: