Reputation: 201
I am new to the concept of rewrite rules on WAMP/Apache/PHP as I usually use ASP.NET and IIS.
I have the following folder structure:
www
|_Content
|_Libs
|_Scripts
|_Views
|_Accounts
|_create-account.php
|_News
|_index.php
|_Media
|_index.php
|_.htaccess
|_about.php
|_index.php
|_WebConfig.xml
I need a rewrite rule to strip .php from all url's. I need another one to stop /View/ from being shown when accessing files from folders with the Views folder
Ideally I would want the url to read: http://host.com/News/ to show when accessing the index.php file in /Views/News/
As mentioned above, I am new to rewrites like this so if someone could point me in the direction of some literature and possibly help me out on this issue it would be greatly appreciated
Thanks you
Upvotes: 2
Views: 115
Reputation: 342
you can get the url and modify in a php file. for example some entered www.yourwebsite.com/homecontorller/homemethod/id/
in your .htaccess file
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
in your bootstrap.php file;
<?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
?>
Upvotes: 1