我是重写的新手,所以我甚至不确定这是否可能。
我有以下URL:http://my.domain.com/index.php?CID=2
我想打字http://my.domain.com/meet-our-team并且上面的页面没有显示真实的url(index.php?CID=2)。
这是我在.htaccess文件中的内容:
RewriteEngine on
RewriteRule ^meet-our-team$ index.php?CID=2 [NC,L]
这似乎将我重定向到我的主页。我该如何进行这种简单的重写?
谢谢,Luke
我发现了两件事:
-
重写代码%{QUERY_STRING}^id=1$重写规则^$http://www.example.com/content/page?[R=301,L]
-
htaccess重定向动态url
@syntrax-谢谢,我也找到了这些和其他类似的帖子,但由于我不相信我正在按照预期的方式使用重写规则,所以无法从中得到太多帮助。
我想做的是创建任何SEF url(例如example.com/这是我的SEF页面),并让它指向一个通常类似于example.com/index.php的url?catid=1$id=5。
看起来我所能做的就是重写原始url中的内容,所以我需要使用这样的方法:http://moz.com/ugc/using-mod-rewrite-to-convert-dynamic-urls-to-seo-friendly-urls
这种方法不能为我创建一个足够干净的sef-url,所以我的解决方案是有一个有效的url列表,将所有指向我的index.php页面:
RewriteRule ^my-sef-url$ index.php
RewriteRule ^my-other-sef-url$ index.php
index.php根据sef映射表检查url,并在数据库中显示基于sef映射的适当页面。这比创建复杂的.htaccess规则要容易得多,并且允许我在sef-url上有更多的灵活性。
例如,您需要使用mod_rewrite将URL相应地重写为.htaccess。
Desired URL = www.yoursite.com/index/users/add/
URL = www.yoursite.com/index.php?controller=users&option=add
.htaccess code :
RewriteRule ^index/(.*)/(.*)'.html index.php?controller=$1&option=$2 [QSA]
因此,您将在get方法变量