user1432124
user1432124

Reputation:

How to change the url with rewrite rule

I have a code

    RewriteEngine On
RewriteCond %{REQUEST_URI} !/(.*).php
RewriteRule ^(.*)$ pages.php?go=$1

Now when i load any other page like fault.php(which is in my directory) then the page loads without external javascript and css

Upvotes: 0

Views: 53

Answers (2)

Brad
Brad

Reputation: 163593

The client thinks you are in a different path.

Try giving a path relative to the root instead. You can easily do this by putting a / in front of the paths, assuming you are relative to the root to begin with.


For example, if normally you access a page here:

/index.php

And, you have some code in that script like this:

<script type="application/javascript" src="js/somescript.js"></script>

And, now instead of index.php, you use something like this:

/something/somethingelse

The client is going to try to load /something/somethingelse/js/somescript.js, but of course the file isn't there. You need to specify it relative to the root, like this:

<script type="application/javascript" src="/js/somescript.js"></script>

Upvotes: 0

Homer6
Homer6

Reputation: 15159

This works for me...

   RewriteEngine On

   # uncomment the following line, if you are having trouble
   # getting no_script_name to work
   # RewriteBase /

   # default front controller
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php [QSA,L]

Upvotes: 1

Related Questions