htaccess 重写下划线、扩展名和尾部斜杠
htacces rewrite underscore, extension and trailing slash
我已经将 htaccess 设置为删除 php 扩展名并添加尾部斜杠。
现在我需要弄清楚如何在同一个 htaccess 文件中用斜杠替换下划线,例如:
- 旧:
http://localhost/website/parentpage_sub-page.php
- 新:
http://localhost/website/parentpage/sub-page/
是否有任何聪明的方法可以为多个网址执行此操作?
这是当前的 htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ // [R=301,L]
提前致谢!
您可以使用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ // [R=301,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/?$ .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ _.php [L]
我已经将 htaccess 设置为删除 php 扩展名并添加尾部斜杠。
现在我需要弄清楚如何在同一个 htaccess 文件中用斜杠替换下划线,例如:
- 旧:
http://localhost/website/parentpage_sub-page.php
- 新:
http://localhost/website/parentpage/sub-page/
是否有任何聪明的方法可以为多个网址执行此操作?
这是当前的 htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ // [R=301,L]
提前致谢!
您可以使用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ // [R=301,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/?$ .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ _.php [L]