简体   繁体   English

htaccess删除.php并重命名文件夹

[英]htaccess to remove .php and rename folder

I'm using php for a native project my urls are as follows project.log/share/report1.php 我正在为本地项目使用php,我的网址如下:project.log / share / report1.php

i want to remove .php from urls, if the url entered contained .php remove it, if not act as if it's found 我想从网址中删除.php,如果输入的网址包含.php,请将其删除,如果没有,就好像被发现了一样

share folder i want to show it as reports too and works vice versa 共享文件夹,我也想将其显示为报告,反之亦然

what i've achieved so far 到目前为止我取得的成就

 RewriteEngine on

RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]

this successfully remove the .php but i don't know how to add an expression for share folder to replace it's name 这样可以成功删除.php,但我不知道如何为共享文件夹添加表达式以替换其名称

You need additional rule to rename share to reports : 您需要其他规则才能将share重命名为reports

RewriteEngine on

RewriteRule ^share/(.*?)(\.php)?$ /reports/$1 [R=307,NC,L]

RewriteRule ^(.+)\.php$ /$1 [R=307,NC,L]

RewriteCond %{DOCUMENT_ROOT}/share/$1.php -f
RewriteRule ^reports/(.*)$ share/$1.php [END,NC]

RewriteRule ^reports/(.*)$ share/$1 [END,NC]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [NC,END]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM