.htaccess to Create Search Engine-Friendly URLs

时光怂恿深爱的人放手 提交于 2019-12-13 16:37:41

问题


I am looking for a way to get rid off the .php extension from my file i have just got a static website with index.php and map.php

I have tried lots of different tutorials but none work i just want the following.

http://example.co.uk/map.php becomes http://example.co.uk/map/

and

http://example.co.uk/index.php becomes http://example.co.uk/

Can you do this with a static file i have tried so many different options and none have worked for me.

i have tried this.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^map/(.*)/$ map.php

Any help please.


回答1:


Try this

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^map/?$ map.php [NC,QSA,L]

RewriteCond %{SCRIPT_FILENAME} \/index\.php [NC]
RewriteRule (.*) http://www.domain.com/ [R=301,L]

# if you have more than one file like map, you can use this
# this will redirect everything to .php like: test/ => test.php
# RewriteRule ^([a-z0-9_\-]+)/?$ $1.php [NC,QSA,L]


来源:https://stackoverflow.com/questions/8053938/htaccess-to-create-search-engine-friendly-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!