문제

I'm using Apache 2.2 and PHP 5.3.8. How should I configure .htaccess to redirect every request do index.php?

I'd like to have URLs like those of stackoverflow or facebook, as: http://mywebsite.com/fancypage where fancypage isn't a directory on the server but just a parameter.

So I thought I needed to redirect every request to a php page, where some code can interpret the $_SERVER['REQUEST_URI'] string. Is this the right way? will $_SERVER['REQUEST_URI'] still be available after the redirection?

도움이 되었습니까?

해결책

Try adding the following to the .htaccess file in the root directory of your site.

It will send all requests (except for existing files/dirs) to index.php.

The original request will be available in the request param.

RewriteEngine On
RewriteBase /

#skip existing files or directories
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
#everything else goes to index.php
RewriteRule ^ index.php?request=%{THE_REQUEST} [L]

다른 팁

What you are interested in is Apache's url_rewrite function. I suggest you visit these two links and research it a bit:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top