Solved

Problems with CSS styles when using .htaccess and mod_rewrite

Posted on 2011-02-11
5
548 Views
Last Modified: 2012-05-11
I am using .htaccess fand mod_rewrite to redirect pages. Basically I would like to do the following:

The link http://www.mydomain.com/movie should be redirected to:

 http://www.mydomain.com/topic.php?p=movie

I am using the following:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-\_\ \%]*)$ /topic.php?p=$1&%{QUERY_STRING}

When I introduce something like http://www.mydomain.com/movie/movie the link is redirected but all the styles and css files are missing.

I mean, if I introduced more than one "/" the redirect is not working properly.

Any idea?

Thanks
0
Comment
Question by:voteg
  • 3
  • 2
5 Comments
 
LVL 8

Assisted Solution

by:rationalboss
rationalboss earned 500 total points
ID: 34877041
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-\_\ \%]*)(/){0,1}$ /topic.php?p=$1&%{QUERY_STRING}
0
 

Author Comment

by:voteg
ID: 34877316
I tryed and still does not work.

The images and css styles are still missing.

Any other suggestion?
0
 
LVL 8

Accepted Solution

by:
rationalboss earned 500 total points
ID: 34877339
I'm sorry I did not get it the first time.

In your template where you put the <link> tags. Use absolute paths:
<link href="http://mysite.com/style/style.css" rel="stylesheet" type="text/css" />

-or-
<link href="/style/style.css" rel="stylesheet" type="text/css" />
0
 

Author Comment

by:voteg
ID: 34877423

It works in the server, but affects all my css files in my local server.

I mean,  if I use <link href="/style/style.css" rel="stylesheet" type="text/css" />my local css does not work. What can I do? I have tryed several things but did not work.

Thanks
0
 
LVL 8

Assisted Solution

by:rationalboss
rationalboss earned 500 total points
ID: 34877443
If you have a configuration file, you can do this:

<?php
if ($_SERVER['HTTP_HOST'] == 'localhost') DEFINE('SITE_LINK','http://localhost/mywebsite/');
else DEFINE('SITE_LINK','http://www.mydomain.com/');
?>

in your template page, just use:
<link href="<?php echo SITE_LINK; ?>style/style.css" rel="stylesheet" type="text/css" />
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ports for sccm 2012 1 81
java continue statement 10 142
WPF issue with Trigger 2 108
PHP_POST() error message 9 60
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question