Forum Moderators: phranque
I`m new here. This is my first post.
I`ve got http://www.example.pl/polish/index.php?sub=main&id=12
Is possible to change this to http://www.example.pl/polish/main/12
or http://www.example.pl/main/12
What i must write in to my .htaccess file?
Sorry for my bad english :)
[edited by: jdMorgan at 6:13 pm (utc) on Dec. 15, 2003]
[edit reason] De-linked, examplified [/edit]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/polish/index.php
RewriteRule ^\?sub=main\&id=$(.*)$ http://www.example.pl/polish/main/$1.php
but it doesn`t work,
Do you have any ideas?
Please help,
Thanks a lot
Luk
[edited by: jdMorgan at 6:13 pm (utc) on Dec. 15, 2003]
[edit reason] De-linked, examplified [/edit]
RewriteEngine on
RewriteRule ^main/([0-9]*) /polish/index.php?sub=main&id=$1
This will rewrite
http://www.example.pl/main/123456
to
http://www.example.pl/polish/index.php?sub=main&id=123456
Not 100% on this but if you use the above line do make sure you put it in a .htaccess file that is in your "main" folder so not in directory polish but itīs parent dir, most likely public_html or www
Anyway, I just needed the above myself today, but after finding out how to do it and getting it working, I ran into a new problem.
Within my page or "set-up" which is:
http://www.example.com/files/21323/ (or without the trailing slash)
being rewritten to
http://www.example.com/file.info?ID=21323
Using this line:
RewriteRule ^files/([0-9]*) file.info?ID=$1
But now to my next problem (the above works fine so thats not it), I also have an option to expand comments on the file, it's url is then
http://www.example.com/file.info?ID=21323&action=expand
(and followed by a #1234 so it "auto-scrolls" down to the comment they want to expand, but that aside)
So what should I rewrite my rule to so that, for example, I can make the expand links:
http://www.example.com/files/21323/expand#1234
(with 1234 being the Comment number to autoscroll to and 21323 being the File ID)
I know you cant do if then statements in apache :) but in pseudo it would be:
if requested url contains "expand" then follow this rule:
RewriteRule ^files/([0-9]*)/expand#([0-9]*) file.info?ID=$1&action=expand#$2
but if it contains no expand then use the rule i already have:
RewriteRule ^files/([0-9]*) file.info?ID=$1
So anyway I have no clue how to handle the above problem, if anyone can shed some light on that issue, thatīd be awesome, thanks in advance!
[edited by: jdMorgan at 6:18 pm (utc) on Dec. 15, 2003]
[edit reason] De-linked, examplified [/edit]
Simply add an [L] flag onto the end of your first rule. If the pattern in the rule matches and the URL is rewritten, then mod_rewrite will quit right there and serve the requested resource from the new URL. If not, it will continue on to the next rule.
In most applications, almost *all* RewriteRules should have an [L] flag.
RewriteRule ^files/([0-9]*)/expand#([0-9]*) file.info?ID=$1&action=expand#$2 [b][L][/b]
RewriteRule ^files/([0-9]*) file.info?ID=$1 [L]
Welcome to WebmasterWorld [webmasterworld.com]!
Here is some more recent discussion of dynamic-to-static URL conversion issues: [webmasterworld.com...]
Jim
RewriteEngine on
RewriteRule ^files/([0-9]*)/expand#([0-9]*) file.info?ID=$1&action=expand#$2 [L]
RewriteRule ^files/([0-9]*) file.info?ID=$1 [L]
However, Iīll fix it with PHP and use
http://www.example.com/files/21323
and
http://www.example.com/files/21323expand#1234
(note no slash before expand)
If PHP finds "expand" in the Query ID it will define $action="expand";
And then strip the word from the ID and check if itīs still a valid number.
That means Iīll have to modify the rewriterule regex but that shouldnīt be a problem so it becomes:
RewriteRule ^files/([0-9expand]*) file.info?ID=$1 [L]
And that works (with the nessesary modifications to my php script) I even like it better like this
http://www.example.com/files/21323x#1234
Anyway thx Jim!
[edited by: jdMorgan at 10:16 pm (utc) on Dec. 15, 2003]
[edit reason] Delinked, examplified URLs [/edit]
In accordance with our charter [webmasterworld.com], we will be happy to help you learn to write this code for yourself, and to help you debug it. However, if you need an immediate solution, you might consider posting in our Commercial Exchange [webmasterworld.com] to hire someone to write it for you.
The following post and the links it contains may be useful to you: Introduction to mod_rewrite [webmasterworld.com]
Jim
I`ve go something like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/polish/index.php?sub=main&id=(.)$ /main/$1.php [L]
but it doesn`t work :(
Please help me change part of url http:.../polish/index.php?sub=main&id=12
to more friendly url http:...../polish/main/(integer).php
I`ve check many rules :(
It is very important for me:(
Please help me.
In order to back-reference the query string, you'll need to use RewriteCond:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^polish/index\.php$ /main/%1.php [L]
It works like this:
The script outputs friendly URLs to browsers and search engine spiders.
The browser or search engine spider then requests friendly URLs.
Mod_rewrite converts friendly-URL requests to requests for your script with a query string.
The script runs, and outputs more friendly URLs, which again may be requested by the browser or spider.
It is important to note *when* mod_rewrite acts; after an HTTP request is received, but before any content is served. For this reason, the usual mod_rewrite action is to translate from friendly to "unfriendly" URLs, not the other way around.
You may indeed have a reason to do the opposite translation - I just want to make sure that the issue is clear.
Jim
I`m so happy, Thank you very much!
But I`ve got only one questione. Is possible change http:.../polish/main35.php to http:.../main/35.php without changing directory? I`ve tried to remove "polish" from RewriteRule ^polish/index\.php$ /main/%1.php [L] but it doesn`t work.