【问题标题】:I want to remove query string added dynamically in a custom php blog CMS我想删除在自定义 php 博客 CMS 中动态添加的查询字符串
【发布时间】:2023-04-10 06:06:01
【问题描述】:

这是页面网址:

https://cmamassociation.in/blog/?action=viewArticle&articleSlug=Javascript-to-hide-URL

为了更好的 SEO 目的,我希望它看起来像:

https://cmamassociation.in/blog/Javascript-to-hide-URL

我使用 .htaccess 尝试了很多东西,但我不太清楚。 我尝试如下:

RewriteEngine On
RewriteBase /
RewriteRule ^index/([a-z]+)/([a-z-]+)$ index.php?action=viewArticle&articleSlug=$2 [NC,L]

【问题讨论】:

  • 你的新 URL 路径不是以 index/ 开头的,那么为什么你的 RewriteRule 试图重写一个呢?
  • @CBore 感谢您抽出宝贵时间。博客文件夹中有一个 index.php 文件,所以我什么时候会使用:cmamassociation.in/blog 它将指向 index.php 文件。

标签: .htaccess redirect mod-rewrite url-rewriting friendly-url


【解决方案1】:

以下列方式保存您的 htaccess 规则文件。这假设您在浏览器中点击链接http://localhost:80/blog/?action=viewArticle&articleSlug=Javascript-to-hide-URL

请确保在测试您的 URL 之前清除您的浏览器缓存。

RewriteEngine On
RewriteBase /
##Rule for external redirect to browser here.
RewriteCond %{THE_REQUEST} \s/blog/?\?action=viewArticle&articleSlug=(\S+)\s [NC]
RewriteRule ^ blog/%1? [R=301,L]

##Rule for internal rewrite here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)/?$ index.php?action=viewArticle&articleSlug=$1 [NC,L]

【讨论】:

  • @Mahendra Varma,您能否让我知道我的解决方案是否对您有用?
  • 感谢 Ravinder 的调查,抱歉我无法查看。只需将其上传到我的博客文件夹/站点上,您的解决方案似乎从 URL 中删除了不需要的字符串,但页面未出现,我收到错误消息,请参阅以下片段:drive.google.com/file/d/1S6Fm9qBzD26KFbdHf_XNjPAL7PXTZSUz/…
  • 有人可以帮我吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-27
  • 1970-01-01
  • 2017-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多