Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 添加.php扩展名(如果不存在)_.htaccess_Url_Mod Rewrite_Url Rewriting_Friendly Url - Fatal编程技术网

.htaccess 添加.php扩展名(如果不存在)

.htaccess 添加.php扩展名(如果不存在),.htaccess,url,mod-rewrite,url-rewriting,friendly-url,.htaccess,Url,Mod Rewrite,Url Rewriting,Friendly Url,我有下面的重写,但我想替换不带扩展名的URL.php如果用户最后用.php键入URL,我如何修改下面的重写脚本 # /m/yyy rule RewriteRule ^m/([\w-]+)/?$ merchants/$1/index.php [L,NC] # /m/yyy/abc rule RewriteRule ^m/([\w-]+)/([\w-]+)$ merchants/$1/$2.php [L,NC] # /m/yyy/abc/ rule RewriteRule ^m/([\w-]+)/(

我有下面的重写,但我想替换不带扩展名的URL.php如果用户最后用.php键入URL,我如何修改下面的重写脚本

# /m/yyy rule
RewriteRule ^m/([\w-]+)/?$ merchants/$1/index.php [L,NC]
# /m/yyy/abc rule
RewriteRule ^m/([\w-]+)/([\w-]+)$ merchants/$1/$2.php [L,NC]
# /m/yyy/abc/ rule
RewriteRule ^m/([\w-]+)/([\w-]+)/$ merchants/$1/$2/index.php [L,NC]

对于所显示的示例,请使用具有以下规则的.htaccess文件。请确保在测试URL之前清除浏览器缓存

RewriteEngine ON
# metchants/yyy/index.php to redirect /m/yyy rule
RewriteRule ^merchants/([\w-]+)/index\.php/?$ m/$1 [R=301,L,NC]
# merchants/yyy/abc.php to redirect /m/yyy/abc rule
RewriteRule ^merchants/([\w-]+)([\w-]+)\.php/?$ m/$1/$2 [R=301,L,NC]
# merchants/yyy/xyz/abc.php to redirect /m/yyy/xyz/abc rule
RewriteRule ^merchants/([\w-]+)/([\w-]+)/index\.php/?$ m/$1/$2 [R=301,L,NC]

# To handle /m/yyy/index.php rewrite rule.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^m/([\w-]+)/?$ merchants/$1/index.php [QSA,L,NC]

# To handle /m/yyy/abc/index.php rewrite rule.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^m/([\w-]+)/([\w-]+)$ merchants/$1/$2.php [QSA,L,NC]

# To handle /m/yyy/xyz/abc/index.php rewrite rule.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^m/([\w-]+)/([\w-]+)/$ merchants/$1/$2/index.php [QSA,L,NC]

你能加几个吗examples@Kelvin,你能告诉我这是否对你有效吗?非常感谢。