【问题标题】:seo friendly / Clean URLs - htaccessseo 友好/清理 URL - htaccess
【发布时间】:2016-03-12 03:58:26
【问题描述】:

我对 Apache / mod_rewrite 完全陌生。我需要这样做

以下网址:

http://www.example.com/applications/seo-friendly-text-for-appA/some-random-php-page.php

应该显示为

http://www.example.com/applications/seo-friendly-text-for-appA

并重定向到位于名为“myappAfolder”的文件夹中的 some-random-php-page.php。我的网络文件夹结构如下:

<example-com-webroot>/applications/myappAfolder/some-random-php-page.php

如果我反其道而行之,比如输入以下网址

http://www.example.com/applications/myappAfolder/some-random-php-page.php

网址应显示为

http://www.example.com/applications/seo-friendly-text-for-appA

但同时重定向到所在的页面

<example-com-webroot>/applications/myappAfolder/some-random-php-page.php

我尝试了 SO 中提到的其他一些解决方案,但到目前为止还没有运气。我已经做了几个小时了

P.N: seo-friendly-text-for-appA 不是文件夹,它不存在于我的网络根目录中

【问题讨论】:

  • 我不知道哪个巨魔对我投了反对票以及为什么

标签: apache .htaccess mod-rewrite seo


【解决方案1】:

您应该为每个文件传递一些 id,例如

http://www.example.com/seo-friendly-text-for-appA ->
http://www.example.com/filename.php?id=seo-friendly-text-for-appA

希望你能写mod_rewrite,网上有很多例子。像这样的:

RewriteEngine On
RewriteBase /
Options +FollowSymlinks
RewriteRule ^([A-Za-z0-9_-]*)$                    /filename.php?id=$1

我认为最好的反向方法是 php,而不是 mod_rewrite。

【讨论】:

  • 我知道在不更改我的 URL 和发送任意 ID 的情况下是可能的。反过来也是可能的,只需使用 htaccess。一旦我得到一些线索,我会发布它。只是我不想以错误的方式去做。还是谢谢
猜你喜欢
  • 2011-05-29
  • 2013-01-22
  • 2013-02-03
  • 2015-04-17
  • 2011-05-09
  • 2015-01-13
  • 1970-01-01
  • 2021-07-23
  • 2014-02-26
相关资源
最近更新 更多