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
.htaccess 需要帮助编写htaccess规则吗_.htaccess - Fatal编程技术网

.htaccess 需要帮助编写htaccess规则吗

.htaccess 需要帮助编写htaccess规则吗,.htaccess,.htaccess,目前我的本地主机URL类似于localhost/apnaujjain/page.php?page_id=1&action=contacts 现在我想写一个规则,这样当我转到上面的url时,它只需重写url,如localhost/apnaujjain/contacts.html 请参阅,它应该将.php转换为.html,而不影响页面内容 直到现在我都试过了 Options +FollowSymLinks -MultiViews RewriteEngine on #RewriteBase / Re

目前我的本地主机URL类似于
localhost/apnaujjain/page.php?page_id=1&action=contacts

现在我想写一个规则,这样当我转到上面的url时,它只需重写url,如
localhost/apnaujjain/contacts.html

请参阅,它应该将
.php
转换为
.html
,而不影响页面内容

直到现在我都试过了

Options +FollowSymLinks -MultiViews
RewriteEngine on
#RewriteBase /

RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]

RewriteCond %{THE_REQUEST} (.*)\.php?page_id=1$&action=2$
RewriteRule ^(.*)\.php $2.html [R=301,L]

RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]

但它不起作用。

您可以在
/apnaujjain/.htaccess
中使用此代码:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /apnaujjain/

# redirect localhost/apnaujjain/page.php?page_id=1&action=contacts to
# localhost/apnaujjain/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2.html? [R=301,L]

RewriteRule ^([^/]+)/([^.]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]

感谢您的快速响应,但是页面id也发生了变化,并且无法在本地主机上工作。让我在服务器上试试,但谢谢,还有如何添加动态页面id,比如Action,当我转到localhost/apnaujjain/index.php时仍然不起作用,然后它会将我重定向到localhost/index.html,当我转到内部页面时,它不会更改url。我在正则表达式方面真的很差,请帮助。根据你的建议,我已经更改了我的url,现在它的,我只是更改了参数位置,因为我只需要url重写中的操作参数,而不需要页面id,所以,现在请建议我确切的规则。是的,这没关系,但实际上,当我们转到其他页面时,页面id也会改变,这就是为什么我只需要将操作名称设置为.html扩展名检查此实时url好的,我已经将我的url更改为以前的url,现在看起来像localhost/apnaujjain/page.php?page_id=4&action=apnaujjain,现在我需要将其转换为localhost/apnaujjain/page_id/action,请尽快回复,谢谢