开发者

.htaccess rewrite frustrations

I made 开发者_开发知识库my website in PHP originally and used parameters for page/product identification.

ex.) http://mysite.com/?pid=my_products&sid=golf_clubs&GTIN=111111111111

I've now moved over to using RoR and I'd like to set up redirects to clean up the urls

http://mysite.com/my_products/golf_clubs/111111111111

I've looked at tutorials and arrived at this:

RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ ?pid=$1&sid=$2&GTIN=$3 [NC]

I've tested a url and it doesn't redirect at all. I've tried putting this in the .htaccess file to debug and chmodded the log folder to 775 but I get a 500 error:

RewriteLog "/home/myaccount/rails_apps/myapp/log/rewrite.log"
RewriteLogLevel 3

As far as rewrite statements in .htaccess goes, this is what I have:

RewriteEngine On
RewriteLog "/home/myaccount/rails_apps/myapp/log/rewrite.log"
RewriteLogLevel 3
RewriteBase /
RewriteCond %{REQUEST_URI} ^/downloads.*
RewriteRule .* - [L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ pid=$1&sid=$2&GTIN=$3 [NC]

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

* I am on a shared hosting plan with Bluehost (good gawd I wish they'd update to Rails 3 soon)


If I understand you correctly, you have your rule backwards. You want to catch your old URLs and rewrite them to the new format, correct? In that case, you want this:

RewriteRule ^\?pid=(\w+)\&sid=(\w+)\&GTIN=(\w+) /$1/$2/$3 [NC,R=301,L]

Adding a 301 status will tell the user agent (including well-behaved search bots) that your canonical URLs have permanently changed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜