Shorten the URL from example.com/page.php?var=letters to example.com/letters

删除回忆录丶 提交于 2019-12-20 06:39:42

问题


I'm kinda new to URL Rewriting in .htaccess , and I tried to do it myself following some tutorials. No success though ....

I want to shorten http://www.example.com/page.php?var=letters to http://www.example.com/letters (letters is only an example).

Any help is very welcomed. Can't get this done myself. :(


回答1:


<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f # if the requested file does not exist
    RewriteRule ^(.+)$ page.php?var=$1 # rewrite the request
</IfModule>



回答2:


A more generic approach, to have all the links you want as domain.tld/person/jon/

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# rewrites all urls to index.php/url
RewriteRule .* index.php/$0 [PT]



回答3:


TRiG's answer should get you up and running however, I would strongly suggest you check out:

.htaccess tips and tricks

It is an excellent tutorial which should help you get your head round this stuff, part 2 covers mod_rewrite.



来源:https://stackoverflow.com/questions/7162369/shorten-the-url-from-example-com-page-phpvar-letters-to-example-com-letters

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