[英]How to remove and redirect .php for subdomains in .htaccess?
I have the following codes to remove the .php extension and redirect the url without the suffix to the right file 我有以下代码来删除.php扩展名并将不带后缀的URL重定向到正确的文件
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
I also have following codes to redirect m.example.com to www.example.com/m/ 我也有以下代码将m.example.com重定向到www.example.com/m/
#mobile
RewriteCond %{HTTP_HOST} ^m\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteRule ^(.*)$ m/$1 [L]
My question is, how should I do the same for files in the m folder, so that 我的问题是,我应该如何对m文件夹中的文件执行相同操作,以便
Thank you. 谢谢。
Combine your rules and remove http://www.example.com/
from target of redirect rule: 合并您的规则,并从重定向规则的目标中删除
http://www.example.com/
:
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]
#mobile
RewriteCond %{HTTP_HOST} ^m\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteRule ^(.*)$ m/$1 [L]
# Resolve .php file for extension-less php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.