重写规则 html/php

Rewrite rules html/php

我目前有这个 .htaccess 代码可以删除 .php/.html 扩展名。

# Apache Rewrite Rules
 <IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /

# Add trailing slash to url
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
  RewriteRule ^(.*)$ / [R=301,L]

# Remove .php-extension from url
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^([^\.]+)/$ .php 

  # Remove .html-extension from url
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.html -f
  RewriteRule ^([^\.]+)/$ .html 


# End of Apache Rewrite Rules
 </IfModule>

我正在尝试让页面 poll.php 成为 /poll/123123/ <-(6 位 ID)来自 poll.php?poll=123123。

我试着加入

RewriteRule ^[A-Za-z0-9-]+/([A-Za-z0-9-]+)/?$ polls.php?poll= [NC,L]

但它随后会尝试检测 dashboard.php 而不是 dashboard.html。

如有任何帮助,我们将不胜感激。

如果您要查找 sp[ecific URL 并且只有数字会发生变化,则不需要通配符

 RewriteRule ^poll/(\d+)/$ polls.php?poll=

或更好,总是 6 位数

RewriteRule ^poll/([0-9]{6})/$ polls.php?poll=

应该可以