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

2020-05-03 08:36发布

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. :(

3条回答
等我变得足够好
2楼-- · 2020-05-03 09:21

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楼-- · 2020-05-03 09:39

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.

查看更多
Deceive 欺骗
4楼-- · 2020-05-03 09:41
<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>
查看更多
登录 后发表回答