Jump to content

Use part of the URL in a rewrite in PHP MVC


imperium2335

Recommended Posts

I am trying to create a rewrite rule that will let me keep the following URL clean:

 

<script type="text/javascript" src="http://www.mysite.com/views/Page/js/jsfile1.js"></script>

 

To be:

 

<script type="text/javascript" src="http://www.mysite.com/js/jsfile1.js"></script>

 

 

When I want to include JS and CSS files in any given view, I call:

$this->view->js = array('Page/js/jsfile1.js', 'Page/js/jsfile2.js') ;

 

 

Where Page would change according to the controller you are currently in.

E.g. If I am on www.mysite.com/contact, any JS I load be redirected to:

 

www.mysite.com/views/contact/js/jsfile1.js

 

But in the header of my contact page you would only see:

 

<script type="text/javascript" src="http://www.mysite.com/js/jsfile1.js"></script>

 

How can this be done? Or does someone know of a better way to not expose the system directories such as /views etc in a PHP MVC framework (this is my own mini custom framework BTW)?

 

I hope I'm making sense!

You cannot have the web-server magically know which folder to go into, it has to get that information from the client.

After all, how would the server know that one call to /js/display.js actually means [/ic]/thread/js/display.js[/ic], but another (identical request) actually means /post/display.js?

 

Also: The referrer is not reliable, a lot of people have it turned off in their browser, or have it modified by proxies etc.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.