Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
Php 是否可以将我的htaccess重写规则压缩为单行规则?_Php_.htaccess_Url Rewriting - Fatal编程技术网

Php 是否可以将我的htaccess重写规则压缩为单行规则?

Php 是否可以将我的htaccess重写规则压缩为单行规则?,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我的Webproject中的所有htaccess规则都起作用。然而,我想知道是否有办法使用REGEX编写一条规则,而不是像下面所示对它们进行硬编码。我在上找不到问题/答案,因此无法满足此处提到的需求。谢谢你的建议和帮助 RewriteEngine on RewriteRule ^index index.php RewriteRule ^about-us about-us.php

我的Webproject中的所有htaccess规则都起作用。然而,我想知道是否有办法使用REGEX编写一条规则,而不是像下面所示对它们进行硬编码。我在上找不到问题/答案,因此无法满足此处提到的需求。谢谢你的建议和帮助

RewriteEngine on

RewriteRule ^index                               index.php 
RewriteRule ^about-us                            about-us.php
RewriteRule ^web-application-development         web-application-development.php
RewriteRule ^mobile-application-development      mobile-application-development.php
RewriteRule ^offshoring                          offshoring.php
RewriteRule ^internet-marketing                  internet-marketing.php
RewriteRule ^careers                             careers.php
RewriteRule ^blog                                blog.php
RewriteRule ^contact-us                          contact-us.php

我正在寻找一个涉及REGEX的单一规则,它完成上述所有规则组合在一起时所做的工作。

您可以使用这个单一规则重写您的.php请求

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [L]
或者,您可以启用多视图来访问不带扩展名的文件,将以下行添加到htaccess中

Options +Multiviews

非常感谢的可能的副本你的要简单得多。伟大的