- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试在我的 PHP 应用程序中实现 URL 重写。有人可以分享在 PHP 和 MySQL 中实现 URL 重写的分步过程吗?
在我的应用程序中,我想实现以下 URL 重写,我想重定向
1. http://example.com/videos/play/google-io-2009-wave-intro
2. http://example.com/videos/play/203/google-io-2009-wave-intro
到
1. http://example.com/videos/play.php?title=google-io-2009-wave-intro
2. http://example.com/videos/play.php?id=203
请告诉我如何以上述任何一种方式实现 URL 重写。
还有一点,从 SEO、管理、应用的角度来看,以下两种类型中哪种 URL 最好。
1. http://example.com/videos/play/google-io-2009-wave-intro
2. http://example.com/videos/play/203/google-io-2009-wave-intro
最佳答案
A Beginner's Guide to mod_rewrite .
通常,这只不过是启用 mod_rewrite 模块(您可能已经在主机上启用了它),然后将 .htaccess 文件添加到您的 Web 目录中。一旦你完成了这些,你就离完成只有几行了。上面链接的教程将为您服务。
只是为了好玩,这里有一个 Kohana用于重写的 .htaccess 文件:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /rootDir/
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/
RewriteRule .* index.php/$0 [PT,L]
这将做的是获取所有请求并通过 index.php 文件引导它们。因此,如果您访问了 www.examplesite.com/subjects/php,您实际上可能正在访问 www.examplesite.com/index.php?a=subjects&b=php。
如果您发现这些 URL 很有吸引力,我鼓励您更进一步,查看 MVC 框架(模型、 View 、 Controller )。它本质上允许您将您的网站视为一组功能:
www.mysite.com/jokes
public function jokes ($page = 1) {
# Show Joke Page (Defaults to page 1)
}
或者,www.mysite.com/jokes/2
public function jokes ($page = 1) {
# Show Page 2 of Jokes (Page 2 because of our different URL)
}
注意第一个正斜杠是如何调用一个函数的,后面的所有内容都填充了该函数的参数。这真的非常好,让网络开发变得更加有趣!
关于php - 如何在 PHP 中重写 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1039725/
我习惯于使用 Apache 服务器,所以当启用 mod_rewrite 时,我可以创建一个 htaccess 文件并使用 URL 重写。 这是我的 htaccess 文件: RewriteEngine
我正在尝试编写一个 mixin 来修改输出的父选择器。这个想法是,在调用 mixin 的情况下,父选择器需要对其进行字符串替换。我有大部分工作,但我不知道如何吞下 & . .test { @inc
我有一个本地目录(上传)和一个 S3 桶设置。 当用户上传图片时,文件存储在本地目录:/uploads/member_id/image_name30 分钟后,系统将文件上传到 S3 使用相同的路径:s
我正在尝试使用以下内容重写代理页面的正文链接: sub_filter http://proxied.page.come http://local.page.com; sub_filte
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 1年前关闭。 Improve this questi
我尝试在我的 JSF 应用程序中使用“重写”(http://ocpsoft.org/rewrite/)。 一切都很好,我已经创建了规则: .addRule(Join.path("/profile/{p
我可以在 AEM 中大致看到两种 URL 重写方法: /etc/map/http(s)下的Sling映射(sling:Mapping) 使用链接重写器/TransformerFactory 重写 UR
我有一个 onclick 函数,我想将 anchor 添加到 href 值。我不想更改 URL,因为我需要该网站仍然可以为没有 javascript 的人/出于 SEO 目的而运行。所以这是我尝试使用
我必须在 UILabel 中显示货币和价格。在一个标签中,但使用不同的字体大小。现在看起来像这样: ...我这样做是重写drawTextInRect:,如下所示: - (void)drawTextIn
我正在尝试使用以下内容进行重定向: RewriteRule ^reviews/area/Santa-Barbara%2F$"/reviews/area/santa-barbara" [R=301,NC
我使用 FOSUserBundle 并且我想覆盖他的 registerAction Controller 。我阅读了与覆盖 FOSUserBundle Controller 相关的文档,但它不起作用。
我正在尝试让 URL 重写在我的网站上运行。这是我的 .htaccess 的内容: RewriteEngine On RewriteRule ^blog/?$ index.php?page=blog
好吧,这让我发疯了......我正在尝试像这样重写我的网址: Now: http://www.somedomain.com/Somepage.aspx http://www.somedomain.co
final方法不能在子类中重写。但凭借 Scala 的魔力,这似乎是可能的。 考虑以下示例: trait Test { final def doIt(s: String): String = s
我有一个类似下面的查询: Select ser.key From dbo.Enrlmt ser Where ser.wd >= @FromDate AND ser.wd ser.wd
我是 nginx 的新手,只是想做一些我认为应该很简单的事情。如果我这样做:- curl http://localhost:8008/12345678 我希望返回 index.html 页面。但是我得
我们的一位客户创建了一个二维码,其中 url 中包含一个空格。 我将如何编写处理此问题的 nginx 重定向? 在字符串中使用诸如“%20”之类的东西的几次尝试似乎会导致 nginx 出错或使 con
我正在尝试覆盖 appendChild 方法,以便我可以控制动态创建的元素并在插入页面之前根据需要修改它们。我尝试了这个示例代码,只是为了看看它是否可以完成: var f = Element.prot
我目前正在使用以下功能,当用户单击某处以确定是否隐藏下拉菜单(在 react 中)。一切正常,但当我单击正文时,它会记录以下内容。 我尝试重写它几次,但我找不到解决这个问题的方法。 Uncaught
我正在开发一个 Spring Integration/Boot 应用程序。我使用多文档 application.yml (src/main/resources/application.yml) 来设置
我是一名优秀的程序员,十分优秀!