简体   繁体   English

htaccess删除PHP和HTML

[英]htaccess to remove PHP and HTML

I have been searching on the Internet for quite awhile now and I can't seem to find a working htaccess for my website. 我已经在互联网上搜索了很长时间,但似乎找不到适合我的网站的htaccess。 I am using a news CMS called CuteNews and they have a function that allows for URL rewrites. 我正在使用一个名为CuteNews的新闻CMS,它们具有允许URL重写的功能。 However, the URL rewrites caused the news pages to become .html as compared to all my other content pages which ends with a .php. 但是,与我所有其他以.php结尾的内容页面相比,URL重写导致新闻页面变为.html。

Instead of forcing the .html to .php or vice versa, I intend to remove both the .php and .html extension from the URL. 我不想将.html强制为.php或反之亦然,我打算从URL中同时删除.php和.html扩展名。 However it can't work despite me putting a few different htaccess that other people had shown in the Internet. 但是,尽管我输入了其他人在互联网上显示的其他htaccess信息,但是它无法工作。

Now, I am really a complete newbie at htaccess because I only have a very limited knowledge about it. 现在,我真的是htaccess的新手,因为我对此的了解非常有限。

This is the .htaccess that CuteNews generates once I activate the URL rewrite functions, 这是我激活URL重写功能后CuteNews生成的.htaccess,

# --- CUTENEWS[ST]
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /cms/show_news.php?cn_rewrite_url=$1 [L]
# --- CUTENEWS[ED]

Can anyone guide me along or something on removing the .html generated by this .htaccess as well as to remove the .php from my other content pages? 谁能指导我进行有关删除此.htaccess生成的.html以及从其他内容页面删除.php的事情? Thanks. 谢谢。

To remove the .php or .html extension add the 2 last lines of this .htaccess extract in your htaccess file : 要删除.php或.html扩展名,请在您的htaccess文件中添加此.htaccess摘录的最后2行:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM