php和url重写
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!
所以我想知道这样的事情是否完全可能。 p>
我希望将 实际示例可能更容易理解 。 所以我希望 我希望这是有道理的。 我真的不好改写。 这甚至可能吗? 我希望排除index.php。 但是,如果无法做到这一点,并且index.php的示例?ect ..将起作用。 谢谢! p>
div> /?directory = $ variable code>更改为类似
/ $ variable code> p>
&lt; a href ='/ {$ variable}'&gt; code>真的是
/?directory = $ variable code>或者在url重写术语中我猜
/?page = $ 1 code> p>
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:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ index.php?directory=$1 [NC,L]