如何将没有变量的 url 重写为包含变量的 url
How to rewrite a url without variables to one containing variables
我是重写的新手,所以我什至不确定这是否可行。
我有这个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]
这似乎将我重定向到我的主页。我怎样才能做这个简单的重写?
谢谢,
卢克
我发现了两件事:
RewriteCond %{QUERY_STRING} ^id=1$
重写规则 ^$ http://www.example.com/content/page? [R=301,L]
htaccess redirect dynamic urls
@syntrax - 谢谢,我也找到了那些和其他类似的帖子,但由于我不相信我正在按照预期的方式使用重写规则,所以无法从他们那里得到太多帮助。
我想做的是创建任何 SEF url(例如 example.com/this-is-my-sef-page)并让它指向 url这通常类似于 example.com/index.php?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 映射 table 检查 url 并根据数据库中的 sef 映射显示适当的页面。这比创建复杂的 .htaccess 规则要容易得多,并且允许我在 sef urls.
上有更多的灵活性
您需要将 URL 相应地使用 mod_rewrite 重写为 .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=&option= [QSA]
因此您将在 GET 方法变量
中获得 "user" 和 "add" 值
我是重写的新手,所以我什至不确定这是否可行。
我有这个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]
这似乎将我重定向到我的主页。我怎样才能做这个简单的重写?
谢谢, 卢克
我发现了两件事:
RewriteCond %{QUERY_STRING} ^id=1$ 重写规则 ^$ http://www.example.com/content/page? [R=301,L]
htaccess redirect dynamic urls
@syntrax - 谢谢,我也找到了那些和其他类似的帖子,但由于我不相信我正在按照预期的方式使用重写规则,所以无法从他们那里得到太多帮助。
我想做的是创建任何 SEF url(例如 example.com/this-is-my-sef-page)并让它指向 url这通常类似于 example.com/index.php?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 映射 table 检查 url 并根据数据库中的 sef 映射显示适当的页面。这比创建复杂的 .htaccess 规则要容易得多,并且允许我在 sef urls.
上有更多的灵活性您需要将 URL 相应地使用 mod_rewrite 重写为 .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=&option= [QSA]
因此您将在 GET 方法变量
中获得 "user" 和 "add" 值