【问题标题】:Clean URL's within subdirectories清理子目录中的 URL
【发布时间】:2020-11-06 15:56:55
【问题描述】:

在对 stackoverflow 进行了大量研究后,我无法弄清楚。 我有一个结构如下的网站

index.php
contact.php
about.html
forum(dir)
   - index.php
   - thread.php

我希望我的 htaccess 做什么

  • 删除.php & .html 扩展名,例如:当您访问联系页面时,url 应该是 www.domain.com/contact/ & www.domain.com/about/
  • 当用户访问论坛时,url应该是www.domain.com/forum/thread/10004000/而不是www.domain.com/forum/thread?id=10004000

我不知道如何弄清楚。我能够删除扩展,但在/“正斜杠”部分失败

这是我的 .htaccess 部分

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

【问题讨论】:

  • 立即尝试,它在我的网站上运行shantunparmar.in,您只需替换为您的文件或文件夹名称
  • 它给出了 403 错误。
  • 你能给我看看你更新的吗
  • 我再次更新了支票
  • 给我一点时间,我正在尝试与我的域相同

标签: php .htaccess subdirectory clean-urls


【解决方案1】:

尝试下面的代码删除 php 扩展,同样可以添加 html

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^forum/thread/(.+) /forum/thread?id=$1 [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

【讨论】:

    【解决方案2】:

    试试这个演示mod_rewritelink

    【讨论】:

      猜你喜欢
      • 2018-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2013-08-20
      • 2016-06-16
      • 2011-05-05
      相关资源
      最近更新 更多