如何添加使用的.htaccess URL重写PHP扩展?重写、htaccess、URL、PHP

2023-09-02 00:28:08 作者:无心亦无情

我已经建立了.htaccess文件在我的网站,该网站显示弹头文本作为网页名称中的URL,但不包括扩展名。 例如实际的URL是

  www.mywebsite.com/page.php?page=about-us
 

然后加载下面的网址,通过URL重写

  www.mywebsite.com/about-us
 

下面是我的.htaccess文件code

 选项+了FollowSymLinks
RewriteEngine叙述上

的RewriteCond%{REQUEST_URI} ^ *!。(图片/ |  .js文件| 的CSS)* $ [NC]。
重写规则^([A-ZA-Z0-9 _-] +)$ /page.php?page=$1
 
PHP中的.htaccess伪静态文件

现在我想告诉所有网页上的PHP扩展,这样的网址应该有如下

  www.mywebsite.com/about-us.php
 

我怎样才能做到这一点?

解决方案

 选项+了FollowSymLinks
RewriteEngine叙述上

的RewriteCond%{REQUEST_URI} ^ *!。(图片/ |  .js文件| 的CSS)* $ [NC]。
重写规则^([A-ZA-Z0-9 _-] +)。PHP $ /page.php?page=$1
 

I have set up .htaccess file on my website which display SLUG text as page name in URL but without extension. e.g. Real url is

www.mywebsite.com/page.php?page=about-us

Then it loads on below url through url rewriting

www.mywebsite.com/about-us

Below is my .htaccess file code

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !^.*(images/|.js|.css).*$ [NC]
RewriteRule ^([a-zA-Z0-9_-]+)$ /page.php?page=$1

Now I want to show the .php extension on all pages, so that the urls should be like below

www.mywebsite.com/about-us.php

How can I do this ?

解决方案

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !^.*(images/|.js|.css).*$ [NC]
RewriteRule ^([a-zA-Z0-9_-]+).php$ /page.php?page=$1