Php htaccess url重写用于文件类型剥离和文件夹
由于我通常使用ASP.NET和IIS,我对WAMP/Apache/PHP上重写规则的概念还不熟悉 我有以下文件夹结构:Php htaccess url重写用于文件类型剥离和文件夹,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,由于我通常使用ASP.NET和IIS,我对WAMP/Apache/PHP上重写规则的概念还不熟悉 我有以下文件夹结构: www |_Content |_Libs |_Scripts |_Views |_Accounts |_create-account.php |_News |_index.php |_Media |_index.php |_.htaccess |_about.php |_index.php |_WebConfig.xml 我需要一个重写规则
www
|_Content
|_Libs
|_Scripts
|_Views
|_Accounts
|_create-account.php
|_News
|_index.php
|_Media
|_index.php
|_.htaccess
|_about.php
|_index.php
|_WebConfig.xml
我需要一个重写规则来从所有url中删除.php。在使用“视图”文件夹访问文件夹中的文件时,我需要另一个视图来停止/查看/显示
理想情况下,我希望url为:
在/Views/News中访问index.php文件时显示/
如上所述,我是一个新的重写像这样,所以如果有人可以指出一些文学方向我,并可能帮助我在这个问题上,这将是非常感谢
谢谢您您可以获取url并在php文件中进行修改。例如,一些人输入了www.yourwebsite.com/homecontorller/homethod/id/ 在.htaccess文件中
RewriteEngine On
RewriteBase /
RewriteEngine On Options All -Indexes RewriteBase /directoryname/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
############### SEO ##########################
#forexample if you don't want someone connect your view folders you can redirect to another page when someone try to enter your wives direct.
RewriteRule ^Views/Accounts 404.php [QSA,L]
#www.yourwebsite.com/homecontorller/homemethod/id
RewriteRule ^(.*)$ bootstrap.php?url=$1 [QSA,L]
# in bootstrap.php if you write echo $_GET['url']; you will see homecontorller/homemethod/id
在bootstrap.php文件中
<?php
echo isset($_GET["url"])
//you can divide the url by slash
$parca = explode("/", $_GET["url"]); //and we divided by slash the url.
//echo $parca[0];//this is first part "/homecontroler/
//echo $parca[1];// and this is second part "/homemethod/;
if($parca[0]=="News")
include "Views/News/index.php";
// we say if the first part is "news" include "news" views/news/index.php file
?>
您不需要任何“文献”,只需查看重写模块的优秀文档即可:非常精确、最新,并附有良好的示例。