开发者

php and url rewrites

so I was wondering if something like this is at all possible.

I was hoping to change /?directory=$variable to something like /$开发者_开发知识库variable

An actual example might be easier to understand. So I want <a href='/{$variable}' > to really be /?directory=$variable or in url rewite terms i guess /?page=$1

I hope this makes sense. I am really no good with rewriting. Is this even possible? I was hoping to exclude index.php on that. however if that cannot be done, and example with index.php?ect.. will work. Thanks!


Yes it's possibile if your server/hosting supports it you can do it by creating an .htaccess file with:

RewriteEngine On
RewriteRule ^/(.+)$ /?directory=$1 [L]

If you want to allow other directories/files to get accessed normally you should do something like:

RewriteRule ^/([a-z]+)$ /?directory=$1 [L]

This will capture any subdirectory like /abc but not /css.css or /customsub/other file

Welcome to the world of SEO optimizer lol.


URL Rewriting is done on the Web Server (Apache, IIS, etc.) and not within a scripting language like PHP.

If you are using Apache, check this out:

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html


RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ index.php?directory=$1 [NC,L]


Read this: http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜