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

风格不统一 提交于 2019-12-13 10:06:30

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/18817471/rewrite-everything-to-index-php-but-be-able-to-know-what-page-it-came-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!