【问题标题】:Htaccess :: parameters with a slash instead of slug=Htaccess :: 带有斜杠而不是 slug= 的参数
【发布时间】:2022-01-14 23:26:07
【问题描述】:

我的主要网址:

localhost/mypage/

我的产品网址:

localhost/mypage/single?slug=UJjd94374

我当前的 htaccess 代码:

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

我希望我的产品 URL 更改为:

localhost/mypage/single/UJjd94374

每次我尝试编写它时,我都会收到 500 个服务器错误,有人可以帮助我了解如何让我的 url seo 友好地使用斜杠而不是 slug= 来设置参数

日志:

[Fri Dec 10 16:26:13.919346 2021] [core:error] [pid 22508:tid 1892] [client 127.0.0.1:51785] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

【问题讨论】:

  • 首先检查错误日志中关于 500 错误的原因。

标签: apache .htaccess url-rewriting


【解决方案1】:

你可以使用这个 htaccess 文件:

RewriteEngine on
#remove .PHP extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)/?$ $1.php [NC,L]
#Shorten the product URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^mypage/single/(.+)/?$ /mypage/single?slug=$1 [L]

【讨论】:

  • 嗨@Amit,当我转到mypage/single?slug=fwytA4xXPNG 时,它可以工作,但是当我输入mypage/single/fwytA4xXPNG 时,它会出现500 错误,当我在帖子中显示日志时,请查看它
  • @DB_cont 您的错误日志显示您的规则正在生成无限重写循环。您的 htaccess 中还有其他规则吗?
  • 不只是你的代码 :: 仅供参考,我的 htaccess 在我的 htdocs 文件夹中,而不是项目文件夹,这会产生差异吗?因为我读到了一些关于 htaccess 在项目文件夹而不是 htdocs 文件夹中的信息。
猜你喜欢
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 2014-12-22
  • 1970-01-01
  • 1970-01-01
  • 2016-07-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多