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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.