开发者

HTACCESS Q. How to redirect index.php?id=directory/indext.html to just a directory?

开发者 https://www.devze.com 2023-04-11 04:37 出处:网络
I can\'t seem to redirect more complex links to directories (with index.php inside) through .htaccess. I have reconstructed and changed files to my site because of the ugly and long URLs:

I can't seem to redirect more complex links to directories (with index.php inside) through .htaccess. I have reconstructed and changed files to my site because of the ugly and long URLs:

Old: www.mysite.com/index.php?id=directory开发者_运维技巧/index.html

New: www.mysite.com/directory/ (with index.php in it, by the way, and not .html anymore).

I also have many directories and not just one that I would like to redirect old links to the new ones, but they all had the ugly index.php?id=somedirectory/index.html after the domain.

Since I have drastically changed my website, the old and ugly URLs open up my homepage with the ugly URL still in the address bar since they all used to use the main .index.php in the root of the site. That's a big no-no for SEO as duplicate content.

By the way, I don't use databases. I use simple PHP files with include() and such now. It's not a WordPress site with member accounts, etc. My website is more static than dynamic.

I hope this is not too confusing. I'm not trying to shorten links with HTACCESS. I'm trying to redirect permanently (301?).

Thank you for your time.


This should do:

RewriteRule ^mysite.com/(.+) mysite.com.index.php?id=$1/index.html [NC]

It works for me!

You will also need:

Options +FollowSymLinks
RewriteEngine on

Above the previous statement.

0

精彩评论

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

关注公众号