Forum Moderators: phranque
I have a link like this:
http://www.mydomain.net/index.php?lang=fr&page=quest
I have set up a htaccess file with the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^pages/([a-z]+)$ index.php?lang=fr&page=$1&nav=$2
and it neatly converts the above link into:
http://www.mydomain.net/pages/quest
The problem arises when I want to add the third and fourth variable, as some links do have it:
http://www.mydomain.net/index.php?lang=fr&page=portfolio&nav=portfolio_press&sub=portfolio_press1
Can you help me add two variables more I can't figure it out?
Thanks.
This does not make sense. Your rewrite should not do what you describe, with or without additional variables.
Please provide a clear description of your "input" URL and query string, and the desired "output" URL and query string. Since the number of parameters can vary, please show several cases.
Jim
Here are several cases of my input queries:
Site 1:
[example.com...]
[example.com...]
[example.com...]
[example.com...]
Desired output:
[example.com...]
[example.com...]
[example.com...]
[example.com...]
Site 2:
[example.net...]
[example.net...]
(the second link is submitted via option menu; it uses a script that lists folder and generates options thus)
Desired output:
[example.net...]
[example.net...]
[example.net...]
etc.
Both sites are multilanguage (the latter being in process of implementing two additional languages), please see - input links are working.
Please help me here.
Thanks a lot.
[edited by: jdMorgan at 4:33 pm (utc) on Feb. 27, 2004]
[edit reason] Examplified URLs per TOS [/edit]
Before tackling the rewrite method needed to solve this problem, it's important to point out a few things:
First, mod_rewrite converts a requested URL into a real URL or a local server filepath. It does this after an HTTP request is received by the server, but before any content is served. In other words, it acts before any files are served, and before any scripts are run. It cannot affect the output from a script, or change the links on a page being served.
I assume that what you are trying to do is to provide users and search engines with "friendly" links that appear to be static, and then convert those into URL-paths with query strings that can be processed by your script.
If this is the case, then the *input* URL is something like "http://www.example.com/pages/en/portfolio/press/1", and the desired output URL-path will be "http://www.example.com/index.php?lang=en&page=portfolio&nav=portfolio_press&sub=portfolio_press1"
Your script will have to generate the "friendly" URLs like "http://www.example.com/pages/en/portfolio/press/1" for output to search engines and users. When one of those URLs is requested by a user or search engine, mod_rewrite can then convert it back into the form needed to invoke your script.
Is this what you want and expect to do? - I want to be sure before spending a lot of time or giving an incorrect answer.
Jim
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^pages/([a-z]{2})/([^/]+)/([^/]+)/(.+)/?$ /index.php?lang=$1&page=$2&nav=$2_$3&sub=$2_$2$4 [L]
RewriteRule ^pages/([a-z]{2})/([^/]+)/(.+)/?$ /index.php?lang=$1&page=$2&nav=$2_$3&sub=$2_$2 [L]
RewriteRule ^pages/([a-z]{2})/(.+)/?$ /index.php?lang=$1&page=$2 [L]
Jim
thanks A LOT - I have implemented it into site 1 - modified some links, added another Rewrite rule to add another level - the whole site is now operational under new links ;)
Site 2 will also be done in the next couple of days.
Again, thanks a lot - I have really learned a lot on mod_rewrite through this.
I owe you BIG! ;)