Mod_rewrite?

design

#1

OK, I’ve moved a portion of my site from HTML to XHTML and PHP. I pretty much had previously used PHP as an advanced kind of SSI, so I originally had added # AddType application/x-httpd-php .html to my .htaccess file. Well, I figured to save some processing on DH’s servers, I’d switch them to be .php files; I’ve also tried to re-structure my site a bit, but I don’t want visitors to the old URLs to get 404 errors, so I thought I’d try a little mod_rewrite action…

Basically, I want to take any request for a file of /ged2html/*.html, and send them to /g2h/*.php (replacing ‘*’ with the requested file). I thought that this might do the trick:

#RewriteEngine on #RewriteRule ^/(ged2html)/(i[0-9][0-9][0-9][0-9]|surnames|persons).html$ /g2h/$2\.php [R=301]but I just get a 404 error (and to qualify, the file names really would be one of surnames.html, persons.html, or ixxxx.html, where the x is a digit)…

Any ideas? Am I totally off-base here?


#2

As a followup, this works:

RedirectMatch permanent /ged2html/(i[0-9][0-9][0-9][0-9]|surnames|persons)\.html$ /g2h/$1.phpbut my understanding is that using Redirect* forces the browser to make an additional request, and is more work for the server (since it has to handle and process another request)


#3

I’m trying to get mod_rewrite to work and saw your post.

Is mod_rewrite in the standard DH php config or did you have to install your own php binary? (How do you get php_info on DH anyhow?)

I’ve tried creating a .htaccess file in the directory my .php pages are in. Contents is simply:
RewriteEngine On
RewriteRule /showcities/([A-Z]+) /showcities.php?st=$1

But I just get the 404 error.

Many thanks


#4

What are you trying to match? What is a typical URL? /showcities/whatgoeshere? Numbers, letters, just letters?

.htaccess and mod_rewrite have nothing to do with PHP, by the way.

  • wil

#5

I want:
www.mydomain.com/showcites/WA

to access my php script as:
www.mydomain.com/showcites.php?st=WA

Oh you’re right! mod_rewrite is an apache module, right? Does DreamHost include it? If so, maybe I’m putting my .htaccess in the wrong place or something. Changes I make thru the DH panel page for htaccess regarding password access seem to work but I don’t see any .htaccess file unless I created one myself.


#6

mod_rewrite is installed.


#7

Are you sure?

I just got email back from Jeff at DH saying it’s not supported. Is he confused?

email from DH customer support follows:

Hello,

Unfortunately, we do not provide support for mod_rewrite. Sorry!
If there is anything more we can help you with, please let us know and we will be more than happy to accommodate!
Thanks! Jeff – DreamHost Support Team + support@dreamhost.com Earn 10-15% for each referral: http://www.dreamhost.com/rewards.html


#8

Providing technical support for something and offering it are two different things. mod_rewrite is installed and will work, however we won’t generally help you out if your rewrite rules aren’t working correctly.


#9

Try

RewriteEngine On RewriteRule ^/showcities/([A-Z]+)$ /showcities.php?st=$1 [L] - wil


#10

Where there’s a Wil[l] there’s a way.


#11

Thanks to Wil’s persistance in helping the helpless (me) plus a bunch of trial and error, I got mod_rewrite working on my site. The following did the trick:

RewriteEngine On
RewriteRule ^showcities/([A-Z][A-Z]) /beta2/showcities.php?st=$1 [R]

Part of the problem was that that I’m running my test one directory level down from the htdocs root ie. in the dir /beta2. I had the .htaccess file in the right place but the trick is how mod_rewrite deals with the directory levels when interpreting the rules. An alternative that also worked was:

RewriteEngine On
RewriteBase /beta2
RewriteRule ^showcities/([A-Z][A-Z])$ showcities.php?st=$1 [R]


#12

Hi, the second example looks a safer bet with the $ anchor at the end. Just to be safe. You could also change that [R] into a [L,R] to instruct mod_rewrite that that really is the last rule for that scenario.

Good luck.

  • wil