Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

apache - Rewrite everything to index.php but be able to know what page it came from.

I need an .htaccess file that rewrite everything to the index.php of my site that is www.examplesite.com.

Example : I open www.examplesite.com/designs/designs.php?tab=2013 and I want the site to load http://examplesite.com/index.php in background, while staying on the same URL. The sub-folder designs and the file designs.php will not exist on the server, and will be loaded from an other server inside of the index.php depending of the entered URL.

My .htaccess already contains some things, I don't really know what it means but I think I need to keep the beginning up to the RewriteCond, I'm not sure about that :

RewriteEngine on

# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.examplesite.com
AuthUserFile /home/designerr/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/designerr/public_html/_vti_pvt/service.grp

RewriteCond %{HTTP_HOST} ^an_other_domain_i_own.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.an_other_domain_i_own.com$
RewriteRule ^/?$ "http://examplesite.com" [R=301,L]

I noticed there is a 301 redirect, I will probably need to build a site-map to be indexed again.

So, what should I put in the new .htaccess ? I also need to know in my PHP code what is the actual URL seen by clients, I think it's with $_SERVER['REQUEST_URI'] or $_SERVER['REDIRECT_URL'], I'm not sure.

*By the way the real name of my sites are not examplesite.com and an_other_domain_i_own.com, but I changed it in this post to ensure that the publication of my .htaccess does not provide you any ways to hack my site or any things like that.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could try these rewrite rules (provided your top line remains: rewrite engine on)

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

These statements direct calls to index.php if the directory & file cannot be found on the server.

REQUEST_URI would provide the url


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...