本文介绍了mod_rewrite将/subpage/更改为/subpage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Okey,所以这是我的问题.我想使用mod_rewrite为我的网站添加漂亮的网址.

Okey, so this is my problem.I want to use mod_rewrite to make nice looking urls for my site.

我希望他们所有人的网址都像www.mypage/tennis或www.mypage/soccer一样好看,而不是www.mypage/?page = tennis和www.mypage/?page = soccer

I want them all to have good looking url like www.mypage/tennis or www.mypage/soccer instead of www.mypage/?page=tennis and www.mypage/?page=soccer

使用以下规则,我可以实现这一目标:

And with the following rules i can achive this:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule .* index.php [L]

所以现在,如果我输入www.mypage/soccer,我的PHP脚本将读取该URL,将其转换为$ _GET ['page'] = football是不可思议的.所有这些都很好!

So now if I type in www.mypage/soccer my PHP script reads this url and does it's magic translating this to $_GET['page'] = soccer. All this works fine!

问题是,如果我突然输入URL www.mypage/soccer/,该网站无法立即找到每个链接的css或图像,因为现在在不存在的文件夹中找到/soccer/.

Problem is if I would type the URL www.mypage/soccer/ all of a sudden every linked css or image cannot be found by the website, since it now looking in the none existing folder /soccer/ off course.

我如何制定将/soccer/转换为/soccer 或将其他任何/blabla/转换为/blabla的重写规则

How do I make a rewrite rule that transforms /soccer/ to /soccer or any other /blabla/ to /blabla

希望我的问题很清楚!另外,如果有人在我能学到更多正则表达式的页面上写得很好,那我将非常高兴!

Hope my question is clear! Also if anyone have any good pages where I can learn more regular expressions i would be very happy!

推荐答案

尝试一下:

RewriteRule ^([A-Za-z0-9-]+)/?$ ?page=$1 [L]

这篇关于mod_rewrite将/subpage/更改为/subpage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 05:07