有人可以向我解释如何使用 mod_rewrite 创建漂亮的永久链接,就像 wordpress 那样吗?
我正在使用 php/mysql 从头开始编写一个网站,并使用 GET 请求在页面之间传递数据。
目前我的链接看起来像:
http://pkh:55/?service=213971&type=FSD
但我想使用 mod_rewrite 使它们更相关,即:
http://pkh:55/FSD/services/football-youth-club/
我已经查看了 wordpress 代码,但我一无所知。
请帮忙!
谢谢 :)
i am writing a site from scratch using php/mysql and am using GET requests to pass data between the pages.
at the moment my links look like:
http://pkh:55/?service=213971&type=FSD
but i would like to use mod_rewrite to make them more relevant, ie:
http://pkh:55/FSD/services/football-youth-club/
i've had a look through the wordpress code but i'm none the wiser.
please help!
thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的站点当前正在通过输出和接受第一种类型的链接进行工作。基本过程是这样的...
确保您的应用程序中有一种方法可以将“football-youth-club”与您通过“213971”检索到的同一组信息关联起来。一般来说,这意味着向数据库表中添加一个永久链接字段。
更新 $_GET 信息的处理,以使用数据库中的永久链接字段而不是 ID。这样您的链接就会看起来像...
http://pkh:55/?service=football-youth -club&type=FSD
更新您网站上所有链接的输出,以便输出第二种格式。
创建 mod_rewrite 规则以将这种漂亮的格式映射到您已实现的功能...
重写引擎开启
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^([azA-Z0-9-]+)/服务/([azA-Z0-9-]+)/? /?service=$2&type=$1
Assuming that your site is currently working by outputting and accepting the first type of link. The basic process is this...
ensure you have a method in your application for associating 'football-youth-club' to the same set of information you retrieve with '213971'. Generally this means adding a permalink field to the database table.
update processing of your $_GET information to use the permalink field in your database rather than the id. So that your links will look like...
http://pkh:55/?service=football-youth-club&type=FSD
update outputting of all links on your site so that it outputs the second format.
create the mod_rewrite rules to map this pretty format to the functionality you have implemented...
RewriteEngine On
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^([a-z-A-Z0-9-]+)/services/([a-z-A-Z0-9-]+)/? /?service=$2&type=$1
请查看此网站。这是我发现过的最伟大的网站之一。请仔细阅读&同时进行一些测试,以便您可以掌握周围发生的情况和情况。如何得到你想要的东西。
还要确保托管服务器已提供使用 HTAccess 和 HTAccess 的权限。 MOD_REWRITE,因为有些服务器默认不提供此权限。如果是这种情况,那么您需要立即向服务器管理员发送请求,要求他提供使用 MOD_REWRITE 和 MOD_REWRITE 的权限。 HTAccess。
希望有帮助。
Please check this website. This is one of the greatest sites I've ever discovered. Please read thoroughly & do some testing simultaneously, so that you can get a grip of what's going around & how to get what you want.
Also make sure that the hosting server has provided permission to use HTAccess & MOD_REWRITE, because some servers don't provide this permission by default. If this is case, then you need to send a request to the server administrator right away, asking him to provide permission to use MOD_REWRITE & HTAccess.
Hope it helps.