Brenden Clerget
Brenden Clerget

Reputation: 137

Use mod_rewrite to change directories to variables... does this work?

If I have a link, for example: dashboard/xyz/fff/ and I use modrewrite to change it to dashboard/?loc=xyz&action=fff when the page loads are loc and action available as variables to use?

If so, then here's a specific example I can't seem to get to work. My rule as it sits:

RewriteRule ^getclients/([a-z\-]+)$ /dashboard/?action=getclients&module=$1

And the link that is sending them to that url:

<li><a href="getclients/seoanalysis" title="SEO Analysis">SEO Analysis</a></li>

I want now to be at .com/dashboard/?action=getclients&module=$1 and use those variables to load the page content that's needed.

However: Now the page redirects to what I believe is the "right page" but the CSS is all broken. I only have plain text. Feel free to suggest another way to achieve the same effect as well perhaps using jQuery and Ajax or something to load up sections of the site.

Thanks!

Upvotes: 1

Views: 127

Answers (3)

anubhava
anubhava

Reputation: 785561

For loading css, images, js files properly from a different relative path you should specify a base URL for all relative URLs on a page like this:

<base href="http://www.example.com/dashboard/" />

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143906

If you don't want to use absolute paths, you can try rewriting the requests for images, javascript, and css. Maybe something like this:

RewriteCond %{REQUEST_FILENAME} \.(js|css|png|jpe?g|gif)$ [NC]
RewriteRule ^getclients/(.+)$ /dashboard/$1  [L]

Upvotes: 1

Corwin Mcknight
Corwin Mcknight

Reputation: 322

Make sure that the file locations are exact, or the server might send the data from the wrong relative directory.

Upvotes: 1

Related Questions