开发者

.htacces & RewriteRule: all links are broken now (after RewriteRule was applied for modifying URL)

After RewriteRule ^([^/]*)/$ /index.php?q=$1 [L] was applied, now you can type mysite.com/aboutus/ as well as mysite.com/?p=aboutus. Now another problem appeared: If you type mysite.com/aboutus/, then the page and pic开发者_开发技巧tures load fine, but links on the page mysite.com/aboutus/ will look like: mysite.com/aboutus/index.php?p=link1 instead of mysite.com/index.php?p=link1 (also mysite.com/link1 would be even better!). How to solve this question? There are too many links to replace them manually.

P.S. Every link looks like <a href="?p=link1" > click here </a> and NOT like http://mysite.com?p=link1.

Thank you.


You can add another RewriteRule:

^(/[^/]+/index\.php\?p=([.]*)$ /index.php?p=$1 [L]

This will make your links valid but redundant. You will still have links like http://mysite.com/path_1/index.php?p=link1 and http://mysite.com/path_2/index.php?p=link1 in your pages.


.htaccess is not in any way responsible for how your software links to things, it rewrites incoming urls from the user, not your HTML files. If the links are made relative to the path, then you end up with the problem you're describing.

If you're the author of the software you don't really have any choice but to replace the links. If you're using some other software it might have an option for search engine friendly urls.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜