【问题标题】:.htacsess url rewrite with few pararms.htaccess url 用几个参数重写
【发布时间】:2021-06-29 03:27:42
【问题描述】:

我有一个网址

 https://exmaple.com/param1/param2/param3/so on .

我希望网址是

https://exmaple.com/param1/param3/so 开启。

这就是我想要做的事情

    <IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^param1/param2/param3/$ /param1/param3/ [L]
</IfModule>

但上面的 url 不起作用并重定向到 404

任何想法

【问题讨论】:

  • 你能展示你的完整 .htaccess 吗?
  • RewriteEngine On RewriteRule ^fussball/land/deutschland/$ /fussball/landing/deutschland/ [L] 这仅在我的 .htaccess 中
  • https://exmaple.com/param1/param2/param3/so 在浏览器中加载时工作正常吗?
  • 是的,工作正常
  • RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule 。 /index.php [L] RewriteRule ^param1/param2/param3/$ /param1/param3/ [L]

标签: php .htaccess url url-rewriting


【解决方案1】:

您可以使用以下规则:

RewriteEngine On
RewriteBase /

RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# match parameter1, parameter2 and remaining URI separately
# capture parameter1 in group #1 and remaining part in group #2
# we are using R=301 to redirect URL externally
# this rule must be placed at the top before last index.php rule
RewriteRule ^([\w-]+)/[\w-]+/([\w-]+/.*)$ /$1/$2 [L,NE,R=301]

RewriteRule ^index\.php$ - [L,NC]

# front controller rule to let index.php handle all non-file/dir URIs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

【讨论】:

  • 这不起作用。它重定向到 404 页面
  • @AayushBansal:在我的本地 Apache 上设置了这些规则后,我会从 /param1/param2/param3/so 重定向到 /param1/param3/so。你在浏览器中输入了什么网址?
  • @AayushBansal:这方面有什么进一步的更新吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多