简体   繁体   中英

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. I am using a news CMS called CuteNews and they have a function that allows for URL rewrites. However, the URL rewrites caused the news pages to become .html as compared to all my other content pages which ends with a .php.

Instead of forcing the .html to .php or vice versa, I intend to remove both the .php and .html extension from the URL. However it can't work despite me putting a few different htaccess that other people had shown in the Internet.

Now, I am really a complete newbie at htaccess because I only have a very limited knowledge about it.

This is the .htaccess that CuteNews generates once I activate the URL rewrite functions,

# --- 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? Thanks.

To remove the .php or .html extension add the 2 last lines of this .htaccess extract in your htaccess file :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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