473,320 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

RewriteRule

I have:
RewriteRule ^([^.]+)/([^.]+)$ ?language=$1&title=$2 [NC]

rewrites domain.com/index?language=en&title=home to domain.com/en/home

Problem: to link to css-files, images etc I have to use '../' to go
into an upper folder, while this shouldn't be necessary. It is because
of de 'folder' 'en' which is in the address field of the browser.

Is there a possibility to resolve this?

Using '/' does not help, because the web app is not in the root.

Thanks in advance
Nov 9 '08 #1
7 3062
On Nov 9, 9:05*am, betty <123be...@gmail.comwrote:
I have:
RewriteRule ^([^.]+)/([^.]+)$ ?language=$1&title=$2 [NC]

rewrites domain.com/index?language=en&title=home to domain.com/en/home

Problem: to link to css-files, images etc I have to use '../' to go
into an upper folder, while this shouldn't be necessary. It is because
of de 'folder' 'en' which is in the address field of the browser.

Is there a possibility to resolve this?

Using '/' does not help, because the web app is not in the root.

Thanks in advance
Add this before the RewriteRule. It will effectively exclude files and
directories from the rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

By the way, it may be easier for you to just use this RewriteRule:
RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]

And parse $_GET['query'] using PHP. That's definitely more flexible.

Thomas

Nov 9 '08 #2
On Nov 9, 3:58*pm, 703designs <thomasmal...@gmail.comwrote:
Add this before the RewriteRule. It will effectively exclude files and
directories from the rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

By the way, it may be easier for you to just use this RewriteRule:
RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]

And parse $_GET['query'] using PHP. That's definitely more flexible.

Thomas
Thank you for your answer.

If I use RewriteCond, I still am having problems with linking files
like css.

Could you tell me how I would be able to 'parse $_GET['query'] using
PHP'? By looking for '/' and extract the values, or is there a better
way to do that?
Is it true that I still would need the RewriteCond?
Nov 9 '08 #3
On Nov 9, 3:58*pm, 703designs <thomasmal...@gmail.comwrote:
On Nov 9, 9:05*am, betty <123be...@gmail.comwrote:
I have:
RewriteRule ^([^.]+)/([^.]+)$ ?language=$1&title=$2 [NC]
rewrites domain.com/index?language=en&title=home to domain.com/en/home
Problem: to link to css-files, images etc I have to use '../' to go
into an upper folder, while this shouldn't be necessary. It is because
of de 'folder' 'en' which is in the address field of the browser.
Is there a possibility to resolve this?
Using '/' does not help, because the web app is not in the root.
Thanks in advance

Add this before the RewriteRule. It will effectively exclude files and
directories from the rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

By the way, it may be easier for you to just use this RewriteRule:
RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]

And parse $_GET['query'] using PHP. That's definitely more flexible.

Thomas
On Nov 9, 3:58 pm, 703designs <thomasmal...@gmail.comwrote:
Add this before the RewriteRule. It will effectively exclude files and
directories from the rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
By the way, it may be easier for you to just use this RewriteRule:
RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]
And parse $_GET['query'] using PHP. That's definitely more flexible.
Thomas
Thank you for your answer.

If I use RewriteCond, I still am having problems with linking files
like css.

With using ?language=$1&title=$2 I can extract the value language by
doing $_GET['language'].
Could you tell me how I would be able to 'parse $_GET['query'] using
PHP'? By looking for '/' and extract the values, or is there a better
way to do that?

Is it true that I still would need the RewriteCond?
Nov 9 '08 #4
On Nov 9, 10:31*am, betty <123be...@gmail.comwrote:
On Nov 9, 3:58*pm, 703designs <thomasmal...@gmail.comwrote:
On Nov 9, 9:05*am, betty <123be...@gmail.comwrote:
I have:
RewriteRule ^([^.]+)/([^.]+)$ ?language=$1&title=$2 [NC]
rewrites domain.com/index?language=en&title=home to domain.com/en/home
Problem: to link to css-files, images etc I have to use '../' to go
into an upper folder, while this shouldn't be necessary. It is because
of de 'folder' 'en' which is in the address field of the browser.
Is there a possibility to resolve this?
Using '/' does not help, because the web app is not in the root.
Thanks in advance
Add this before the RewriteRule. It will effectively exclude files and
directories from the rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
By the way, it may be easier for you to just use this RewriteRule:
RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]
And parse $_GET['query'] using PHP. That's definitely more flexible.
Thomas

On Nov 9, 3:58 pm, 703designs <thomasmal...@gmail.comwrote:
Add this before the RewriteRule. It will effectively exclude files and
directories from the rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
By the way, it may be easier for you to just use this RewriteRule:
RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]
And parse $_GET['query'] using PHP. That's definitely more flexible.
Thomas

Thank you for your answer.

If I use RewriteCond, I still am having problems with linking files
like css.

With using ?language=$1&title=$2 I can extract the value language by
doing $_GET['language'].
Could you tell me how I would be able to 'parse $_GET['query'] using
PHP'? By looking for '/' and extract the values, or is there a better
way to do that?

Is it true that I still would need the RewriteCond?
I think that the easiest way is to use split, as in:

$params = split("/", $_GET['query']);
http://us3.php.net/split

In this case, URLs would be written like this:
/language/title
and be mapped to
/index.php?query=language/title

Thomas
Nov 9 '08 #5
betty escribió:
RewriteRule ^([^.]+)/([^.]+)$ ?language=$1&title=$2 [NC]

rewrites domain.com/index?language=en&title=home to domain.com/en/home

Problem: to link to css-files, images etc I have to use '../' to go
into an upper folder, while this shouldn't be necessary. It is because
of de 'folder' 'en' which is in the address field of the browser.

Is there a possibility to resolve this?

Using '/' does not help, because the web app is not in the root.
The browser doesn't know/care about the server's disk layout. If you add
slashes to the URL you *are* adding directory levels. So you have
several alternatives:

1. Replace slashes with anything else:

http://example.com/en-home

2. Fix your relative URLs, adding "../" as you said; it *is* necessary.

3. Build absolute URLs. PHP is a programming language, it should not be
a big issue to replace / with the appropriate value for your system ;-)
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Nov 10 '08 #6
betty wrote:
>I have:
RewriteRule ^([^.]+)/([^.]+)$ ?language=$1&title=$2 [NC]
I have had this problem ...

Just use <basehtml tag and problem should go away :-) Or use full URI in your
css include path etc.

Nov 10 '08 #7
Thanks to all for helping out.

I use now:
<base href="http://
<? echo $_SERVER['SERVER_NAME'];
echo substr($_SERVER['SCRIPT_NAME'], 0,
strrpos($_SERVER['SCRIPT_NAME'], '/'));
?>
/" />
<link rel="stylesheet" href="css/main.css" type="text/css" />
Using only <base /is not good: when moving the website to another
folder, I have to change <base />.
Using only PHP to find the root folder, isn't good too: I have to put
it everywhere in the file when linking to a file like css or image.

SO I'm using a combination of both.

Is using $_SERVER['SERVER_NAME'] and $_SERVER['SCRIPT_NAME'] the
safest?
Nov 11 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Phil Powell | last post by:
http://www.sitepoint.com/article/910/2] How can it be possible to use Apache's mod_rewrite module in such a way as to dynamically feed it variable information into the "RewriteRule" option? I...
13
by: Stephen Kay | last post by:
Is there a way to redirect every single page on an existing web site through a php function? In other words, say I have a whole functional HTML web site, never written to use any php. Now I...
3
by: aljosa.mohorovic | last post by:
..htaccess file: RewriteRule ^test$ test.php RewriteRule ^test\/(.*)$ test.php/$1 my guess is that result should be equal: http://koncar.info/test.php/anything http://koncar.info/test/anything...
7
by: Jon Maz | last post by:
Hi, I'm having problems with a RewriteRule that's applied to url's with the % character in them, hope someone can help. The % character is a result of url-encoding non-ASCII words, as in the...
2
by: RuthC | last post by:
Hi, In my website there is a facility for user to create there own pages we are maintaing this url as www.mywebsite.com/mypage/user created page name ex : www.mywebsite.com/mypage/ruth user...
1
by: dheeraj4uuu | last post by:
Hii I have an Smf forum, and i installed SEO4SMF to my forum and i made some modifications to my htaccess file.but after doing so everything works fine but i noticed that after going to some...
2
by: JackpipE | last post by:
I need to rename a generic image to the name of the product that's being viewed on the page: /theme/images/fullProfile.gif to - /theme/images/ productxxx.jpg The productxxx.jpg image...
0
by: macaco | last post by:
I'm trying to achieve the following: anydirectory/index.php?query_str --> anydirectory/index2.php?query_str anydirectory/anysubdirectory/index3.php?query_str -->...
0
Claus Mygind
by: Claus Mygind | last post by:
I have a helpDesk app. that sits on a server only accessible to our web users within our building. But we also have offices in other buildings through out the State. I would like to give access...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.