Forum Moderators: phranque
Welcome to WebmasterWorld [webmasterworld.com]!
The URL displayed when you hover over a link on a page cannot be changed by mod_rewrite, because mod_rewrite only changes URLs received in HTTP requests by the server before any content is serveb; Whatever URL is in the link code on the page will be displayed.
Or, if I misunderstand what you're saying, you may just have a bug in your RewriteRule. If so, post your code with the domain name changed to 'example.com' and let us have a look at it.
Jim
RewriteEngine on
Options FollowSymlinks
RewriteBase /
RewriteRule ^\.htaccess$ - [F]
RewriteRule ^index/(.*)/(.*).php /index.php?fuseaction=$1.$2 [L]
It's ok that the hover links are not changed, but the links are not changed in the Address field on IE even when they are clicked on.
Please advise.
Thanks.
RewriteRule ^index/[b]([^/]*)/(.*)\.p[/b]hp /index.php?fuseaction=$1.$2 [L]
If you really do want these query strings to show in browsers and search engine listings, then make it an external redirect:
RewriteRule ^index/([^/]*)/(.*)\.php http://www.example.com/index.php?fuseaction=$1.$2 [R=301,L]
Jim
jdMorgan, thanks for explaining this again, I've been trying to get that working for a month, something in your explanation finally clicked. I have another question:
say you want to rewrite as above, but with the option of having either one or two items in the query string, like this:
rewriting to:
index.htm?section=something&page=4
or:
index.htm?section=something
I tried various ways to do that, and always ended up with a 500 error. Mod_rewrite is very hard to understand.
RewriteEngine On
RewriteRule ^(.*)/page(.*)\.htm /index.htm?section=$1&page=$2 [NC]
this works.
but this:
RewriteEngine On
RewriteRule ^(.*)/page(.*)\.htm /index.htm?section=$1&page=$2 [NC]
RewriteRule ^(.*)/ /index.htm?section=$1 [NC]
doesn't, I'm sure there's something basic wrong in how I'm doing it. In other words, I want an if type situation: if address is mysite.com/main/page0.htm then the first rewrite rule applies (this currently works), but if it's
mysite/main/ the second rewrite rule applies. Does this make sense?
Short answer: You may just need to use an [L] flag on your first rule, so that the rewrite engine quits if the first rule is applied. (Always use an [L] flag unless you have a known reason not to.)
Long answer: See this thread [webmasterworld.com] for one way to take apart a long friendly URL and build a complex query string, allowing for missing parameters and parameters in any order. This method depends on having "keys" in the friendly url, so that the parameter order can be discerned.
Jim
I am tyring the example you linked 1373 to used keys for multiple parameters. This is what I'm trying to do:
Convert:
[localhost...]
To friendly:
[localhost...]
But this code is not working:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index(.*)/parameter4_([^/]+)(.*)$ index$1$3?parameter4=$2 [QSA]
RewriteRule ^index(.*)/parameter3_([^/]+)(.*)$ index$1$3?parameter3=$2 [QSA]
RewriteRule ^index(.*)/parameter2_([^/]+)(.*)$ index$1$3?parameter2=$2 [QSA]
RewriteRule ^index(.*)/parameter1_([^/]+)(.*)$ index$1$3?parameter1=$2 [QSA]
RewriteRule ^index(.*)/([^/]*)/(.*)(.*) index$1$4?fuseaction=$2.$3 [QSA]
RewriteRule ^index /index.php [L]
Please advise.
Thanks.
Chuender
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index(.*)/parameter4_([^/]+)(.*)$ index$1$3?parameter4=$2
RewriteRule ^index(.*)/parameter3_([^/]+)(.*)$ index$1$3?parameter3=$2 [QSA]
RewriteRule ^index(.*)/parameter2_([^/]+)(.*)$ index$1$3?parameter2=$2 [QSA]
RewriteRule ^index(.*)/parameter1_([^/]+)(.*)$ index$1$3?parameter1=$2 [QSA]
RewriteRule ^index/([^/]+)/([^/]+) index?fuseaction=$1.$2 [QSA]
RewriteRule ^index /index.php [L]
Also, there are simpler ways to do this *if* your parameters are always presnet and always in the same order in the friendly URI. The above code is flexible, but slower.
Jim
Sorry about being vague - should have known to check the error log.
[Sat Apr 24 22:51:22 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 0/10., referer: [localhost...]
[Sat Apr 24 22:51:22 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 1/10., referer: [localhost...]
[Sat Apr 24 22:51:22 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 2/10., referer: [localhost...]
[Sat Apr 24 22:51:22 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 3/10., referer: [localhost...]
[Sat Apr 24 22:51:22 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 4/10., referer: [localhost...]
[Sat Apr 24 22:51:22 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 5/10., referer: [localhost...]
[Sat Apr 24 22:51:22 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 6/10., referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 7/10., referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 8/10., referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 9/10., referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] mod_rewrite.c(1744): [client 127.0.0.1] mod_rewrite's internal redirect status: 10/10., referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [error] [client 127.0.0.1] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary., referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] core.c(2694): [client 127.0.0.1] r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:23 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:24 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:24 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:24 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index.php, referer: [localhost...]
[Sat Apr 24 22:51:24 2004] [debug] core.c(2700): [client 127.0.0.1] redirected from r->uri = /index/products/showMain.php, referer: [localhost...]
Why is it doing all these redirects?
These parameters are not always present, plus there may be more parameters in the future so I thought this is a good way to go.
Appreciate all your help.
Chuender.
[localhost...]
And this is what my mod_rewrite look like:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^index/([^/]+)/([^/]+)/([^/]+)$ index$1$3?by=$2
RewriteRule ^index/([^/]+)/([^/]+)/([^/]+)$ index$1$3?display=$2 [QSA]
RewriteRule ^index/([^/]+)/([^/]+)$ index?fuseaction=$1.$2 [QSA]
RewriteRule ^index index.php [L]
It works when I use:
[localhost...]
But it seems to loose the fuseaction when I use:
[localhost...]
Please advise.
Thanks.
RewriteRule ^index(.*)/parameter4_([^/]+)[b](.*)[/b]$ index$1$3?parameter4=$2
RewriteRule ^index/([^/]+)/([^/]+)/[b]([^/]+)[/b]$ index$1$3?by=$2
Ref: [etext.lib.virginia.edu...]
Jim
It FINALLY works, but not sure why...
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteBase /
RewriteRule ^index/(.*)/(.*)/(.*)/(.*)$?fuseaction=$1.$2&display=$3&by=$4
RewriteRule ^index/(.*)/(.*)/(.*)$?fuseaction=$1.$2&display=$3 [QSA]
RewriteRule ^index/([^/]+)/([^/]+)$ index?fuseaction=$1.$2 [QSA]
RewriteRule ^index index.php [L]
It was more like a game - I looked at $_SERVER['QUERY_STRING'] to figure out what was going on and changed my statements to get the output to match.
I this thing ugly or what?
Thanks for all your help, really appreciate it.
Chuender.