开发者

How to redirect an url with parameters?

I'm at a total loss trying to integrate a mod_rewrite in my existing page. Currently, I am building a new site from scratch, and there i have some nice clean url's开发者_如何学Go such as:

http://www.example.nl/nl/example

The old site, running Cms made simple, has some not-rewritten url's that would need to be redirected to the new pages. Those url's look like this:

http://www.example.nl/index.php?page=cake-and-pie&hl=nl_NL

But shorter versions of that like:

http://www.example.nl/index.php?page=cake-and-pie

also work.

It took me a while to figure out that url's with parameters cannot simply be redirected with "Redirect 301", like i'd normaly do. So i tried some online mod_rewrite generators like this and this, but the rules outputted by those result only in 404 errors, (the redirect doesn't work at all).

My .htaccess file current looks like this:

RewriteEngine On
RewriteBase /

# remove .php;
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

# remove index
RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

The old pages would seize to exist. How do i redirect the old pages to the new ones?

Thanks.

EDIT

RewriteCond %{QUERY_STRING} =page=pie
RewriteRule ^index\.php$ /nl/? [L,R=301]
RewriteCond %{QUERY_STRING} =page=pie&hl=nl_NL
RewriteRule ^index\.php$ /nl/? [L,R=301]

Seems to do the trick. This is of course manual for every url, but i only have a few.


RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/([^/]+)/?$    index.php?page=$1&hl=$2
RewriteRule ^([^/]+)/?$         index.php?page=$1 [QSA]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜