如何添加使用的.htaccess URL重写PHP扩展? [英] How to add .php extension using .htaccess url rewriting?

查看:217
本文介绍了如何添加使用的.htaccess URL重写PHP扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了.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扩展,这样的网址应该有如下

  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

这篇关于如何添加使用的.htaccess URL重写PHP扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆