Htaccess redirect?


#1

Alright, so I’m trying to make URLs that are folder/index.php?id=variable#here redirect server-side when in the address bar a user types in folder/variable#here.

I’ve searched a few .htaccess help sites, including a few forums, but they didn’t help with why what I’m doing is not working. Here’s my current code:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^folder/(.+) index.php?id=$1 [nc]

The htaccess file is in the folder that would be displayed server-side (folder).

I also have tried this code:

Options +FollowSymlinks
RewriteEngine ON
RewriteBase /
RewriteRule ^/folder/([0-9]*) /folder/index.php?id=$1 [L]

I’ve also asked on another forum, and apparently that’s correct. I’m thinking maybe mod_rewrite is for some reason not enabled with DreamHost?


#2

A friend just supplied me with a redirect .htaccess code today:

Redirect permanent /site2/ http://www.domain2.com/
Redirect permanent /site2 http://www.domain2.com

Havent tried it yet but I hope it works!


#3

Mod rewrite does work on DH. Not sure about rewritebase if thats allowed or not, I haven’t seen that one yet.
Question do you have an index.php file in each folder, or are you trying to parse each folder with the same index.php file?
Silk

My website


#4

This is easily overlooked, but it is in the Apache documentation…

The directory prefix is stripped from the URL when processing RewriteRules in per-directory configuration files (.htaccess)

Let’s say you want to map http://example.com/contact to http://example.com/index.php?page=contact

Your URL-path is /contact

Your .htaccess file is /home/username/example.com/.htaccess

Thus your directory prefix is /

Thus the string your matching against is ‘contact’

Thus your pattern should start with ^contact

Hope that makes sense. Here is another example.

Your URL is http://example.com/pages/contact

Thus your URL-path is /pages/contact

But your .htaccess file is /home/username/example.com/pages/.htaccess

Thus your directory prefix is /pages/

Thus the string your matching against is ‘contact’

Thus the pattern should still start with ^contact

:cool: [color=#6600CC]Atropos[/color] | openvein.org


#5

you can ignore the #here because that’s all handled by the browser anyway and doesn’t get sent as part of the request.

i like your second rule except for a couple things. i use mod_rewrite a lot and haven’t needed RewriteBase. if .htaccess is in the document root, it should work with just this:

RewriteEngine on
RewriteRule ^folder/([0-9]*) folder/index.php?id=$1

i’d leave off the [L] to have the URL stay as folder/variable#here – otherwise it will actually change to folder/index.php?id=variable and might drop the #here

the [0-9]* is better than .+ because .+ will also match index.php?id=variable, and you don’t want that!


#6

Unfortunately, that didn’t work either. :frowning:

As to the post before that, I have no clue what to do with all of that post. I’m not THAT nerdy. :stuck_out_tongue:


#7

Eh…Copy/pasting from other websites is frustrating, you should try to put things in your own words so it makes a little more sense.

Anyway, basically the code should now be:

Options +FollowSymlinks
RewriteEngine ON
RewriteRule ^/$1/([0-9]*) /index.php?id=$1 [L]

Right?

That didn’t work either. :expressionless:

when I go to my site (/folder/555252/) I get the “Page not found” error still. This is way too frustrating.


#8

Alright, so let me give a more specific example:

My .htaccess folder is in the root folder (gql.yellow-ducky.com) . . .

http://gql.yellow-ducky.com/555252

Should SERVER-SIDE redirect to http://gql.yellow-ducky.com/folder/index.php?id=555252

Or whatever other number that’s there.

I’m not sure what else to try and I don’t think someone in DH support would be able to help me with something like this…


#9

I still never solved my issue, and I’m not sure what I can do next.


#10

You’ve already been told to remove the leading slash in your RewriteRule.

This:

RewriteRule ^/folder/([0-9]*) /folder/index.php?id=$1 [L] Should be written like this:

RewriteRule ^folder/([0-9]*) /folder/index.php?id=$1 [L]

Perhaps you shouldn’t attempt technical things (and mod_rewrite certainly qualifies, despite the proliferation of copy/paste rules out there) if you’re unwilling to RTFM. I’m sure you can find lots of people who would be willing to fix this for you in exchange for a consulting fee.


If you want useful replies, ask smart questions.


#11

for http://gql.yellow-ducky.com/555252, mod_rewrite in the root directory (i.e. /home/username/gql.yellow-ducky.com/ unless you picked something else) sees 555252, so to match that and anything else numeric, you can use a rule like this: ^[0-9] $ – the ^ matches the beginning, the $ the end, and [0-9] means at least one digit.

so to redirect http://gql.yellow-ducky.com/555252 to http://gql.yellow-ducky.com/folder/index.php?id=555252, this rewriterule should work:

RewriteRule ^([0-9] )$ /folder/index.php?id=$1 [L]

note the [0-9] is now enclosed in parenthesis – this is so that it will be available as $1 for the rewrite.

i’m not sure if this is actually what you want though since you sometimes say you’re going for /555252 and other times say /folder/555252

track7 - my dream-hosted site


#12

misterhaan, you are a super help! I actually don’t remember seeing the dollar sign in any rewrite codes before, only separately with a short description that didn’t make sense to try it.


#13

glad to help! also, there were supposed to be plus signs in what i posted (the [0-9] always should have been followed by one, but it seems to have been converted into spaces…)

track7 - my dream-hosted site