I currently have my own URL开发者_如何学C Shortening service.
How would I go about writing the .htaccess file so that if you go to http://www.xxxxx.com/shorturl it'll treat the shorturl as the shortened url (instead of a directory) and pass it on to the decoder.php file as a $_GET variable?
Try the following in a .htaccess file in the web root of your server, it's a pretty standard use of mod_rewrite. If it already exists with some other Rewrite rules just tack the block on to the end of your .htaccess file without the RewriteEngine On bit.
<IfModule mod_rewrite.c>
# Turn on the rewrite engine
RewriteEngine On
# If the page doesn't really exist, run it through decoder.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+)/?$ decoder.php?id=$1 [QSA,L]
</IfModule>
You are looking for mod_rewrite. Information abounds at your favourite search engine.
Try this: https://stackoverflow.com/a/15642716/2131877
there you will see how to endoce url before you send that as a $_GET parameter, because the special symbols of link =&:// has to be encoded before they are passed.
加载中,请稍侯......
精彩评论