homepage Welcome to WebmasterWorld Guest from 54.197.110.151
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

This 117 message thread spans 4 pages: < < 117 ( 1 [2] 3 4 > >     
URL rewrite help needed
nevski



 
Msg#: 4595719 posted 12:52 pm on Jul 23, 2013 (gmt 0)

Hi this is my first post on this forum.
The content of this forum is great,so keep up guys!

I have a problem with url rewriting.

This is my test page that I'm using for this purpose:
http://example.com/

I want to rewrite url:

http://example.com/index.php?page=about

to

http://example.com/about



or to be more precise to rewrite any page that contains
index.php?page=
to
http://example.com/$GET
variable name.

Content of .htaccess file is:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1


The problem is that url rewrite doesn't change in address bar it stays the same when I access to it by link on my navigation bar the link is:

<li><a href="index.php?page=about">About</a></li>


Adress bar:
http://example.com/index.php?page=about


But when I type manualy in address bar

http://example.com/about


it opens page correctly

So where is my mistake?
Any help guys?I would appreciate it!Tnx in advance!

[edited by: phranque at 2:24 pm (utc) on Jul 23, 2013]
[edit reason] Please Use Example.com [webmasterworld.com] [/edit]

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4595719 posted 9:22 am on Jul 27, 2013 (gmt 0)

If requesting
http://localhost/index.php?page=about displays the correct content when the redirecting rule and it's conditions are all commented out (add a # to the start of each line), then the PHP script is working fine.

If the URL I just quoted is incorrect, then use the correct one (perhaps there's a folder level to be included?), and make sure that correction is included within all of your rules.

Next, request
http://localhost/about and at this point it doesn't matter whether the redirecting rule and its conditions are commented out or not, but the rewriting rule must NOT be commented out.

If this fails to show the correct content, then you haven't specified the right internal target. The target should begin with a slash. Is there a folder name involved, that hasn't been stated in the rule target?

Once the rewriting part is working, uncomment the redirecting rule and its conditions. Requesting
http://localhost/index.php?page=about (or http://localhost/foldername/index.php?page=about if there is a folder involved) should redirect to the new format URL and then show the correct content.
nevski



 
Msg#: 4595719 posted 10:45 am on Jul 27, 2013 (gmt 0)

Tnank you guys you are making me happy seriously))You are so profound and I really appreciate it!

Structure of my website looks like this:

<?php
if ($_GET['page'] == ''){
$pg='home';
}
else {
$pg=($_GET['page']);
}

?>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test website</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="wrapper">
<div id="header"><h1>Header</h1></div>
<div id="nav_main">
<ul>
<li><a href="index.php?page=home">Home</a></li>
<li><a href="index.php?page=about">About</a></li>
<li><a href="index.php?page=contact">Contact</a></li>

</ul>


</div>
<div id="content">
<div id="content_right"></div>
<div id="content_main"><?php include('content/'.$pg.'.php') ?> </div>

</div>
<div id="footer">Footer</div>
</div>
</body>
</html>


So it basicly says when the page is opened to see look out for the name of variable,and after that so decide what page from content will open.

if ($_GET['page'] == ''){
$pg='home';
}
else {
$pg=($_GET['page']);
}


If the variable is '' (none) then it will send us to home,if $GET is different it will send us to page that is equal to
name of $GET variable.

<div id="content_main"><?php include('content/'.$pg.'.php') ?> </div>


So the radirecting works nice since i get the result that I wanted on browser address bar...www.example.com/$GET[].
R=301 in that rule permanently redirects ugly url to better looking new one,and L prevents endless loops.

But next goal is to extract $GET from prettier url so the browser can load the page.


So do I have to do manual change of links in the content area of website from:

<a href="index.php?page=about"> to <a href="/about"> ?


When I hower over link without changes it shows old ugly url in bottom part of browser,not the clean url.Just to answer to your question))

So I've made file widgets.html,wrote the rule
RewriteEngine on
RewriteCond %{THE_REQUEST} \?
RewriteCond %{QUERY_STRING} page=([a-z]+)

RewriteRule ^index\.php$ localhost/%1? [R=301,L]
RewriteRule /about widgets.html [L]


and it doesn't show anything still 404 error and the page exists for sure.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4595719 posted 12:12 pm on Jul 27, 2013 (gmt 0)

RewriteRule /about widgets.html [L]

There's at least one error in the code in that quote.

If requesting the URL

http://localhost/widgets.html

works OK and directly shows the correct file contents when there is no .htaccess file, then your rewriting rule should be

RewriteRule ^about$ /widgets.html [L]

for when you request

http://localhost/about

A request for "about" makes the server internally fetch "widgets.html". This is a rewrite.

In a rewriting rule, the requested new URL path goes on the left and the real filename found on the server hard disk goes on the right.

----

To complete the example, the matching redirecting rule would be

RewriteCond %{THE_REQUEST} [A-Z]{3,9}\ /widgets\.html\ HTTP/
RewriteRule ^widgets\.html$ http://localhost/about [R=301,L]


and would be listed before the rewriting rule.

A request for "widgets.html" results in the browser being told to make a new request for the new
http://localhost/about URL. This is a redirect.

In a redirecting rule, the URL path (and only the path, not hostname, not parameters) used in old-style requests goes on the left and the new URL including protocol and hostname goes on the right.

The
RewriteCond looking at %{THE_REQUEST} prevents an infinite loop. In this case it looks again at the requested path.

In your real site the RewriteCond will also look at the requested parameters attached to the URL request.

----

Another crucial part is to manually update the href links on your pages so that they also use the new URL format.

nevski



 
Msg#: 4595719 posted 5:10 pm on Jul 27, 2013 (gmt 0)

I never thought that mod_rewrite would cause such pain for me)))

I want to finish and make correct this code that I've started:

RewriteEngine on
RewriteCond %{THE_REQUEST} \?
RewriteCond %{QUERY_STRING} page=([a-z]+)
RewriteRule ^index\.php$ http://localhost/%1? [R=301,L]
RewriteRule ^([a-z]+)$ /index.php?page=$1 [L]

So I have read this thread also

[webmasterworld.com...]

I guess the content is very similar to my desired rewrite and redirect.

Part 2. Rewrite
You get an incoming request for a short pretty URL-- either from a new arrival or from someone who was redirected in Part 1. The server can't tell the difference.

RewriteRule blahblah/([a-z]+)$ longcomplicatedURL?queryname=$1 [L]

Since that in url I don't have blalalal anymore becuase it is redirected to format [localhost...] i need to do internal rewrite of this url [localhost...] extract variable after http://localhost and rewrite it in a form that exists on page so $GET will be fetched on my page content will be loaded.

So my goal is to say by rewrite rule capture the part of link as variable from localhost/about and rewrite it on the index.php?page=variable

RewriteRule ^([a-z]+)$ /index.php?page=$1 [L]

But no matter what I've tried it doens't work at all.
Can someone just point my mistake,I'me really frustrated with it,of course it is not your fault.I'm trying to figure it out is my logic with taking variable from redirected link
and capture it and then passing it like in my code right,or wrong?

[edited by: phranque at 5:25 pm (utc) on Jul 30, 2013]
[edit reason] unlinked url [/edit]

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4595719 posted 7:34 pm on Jul 27, 2013 (gmt 0)

In the post before yours we were discussing your simple test with a widgets.html file. I wanted to continue with that until you had it working. The simple example would likely expose where the error is.

Get the example with widgets.html working 100% first and then proceed to the more complicated example after that.

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4595719 posted 9:56 pm on Jul 27, 2013 (gmt 0)

then your rewriting rule should be

RewriteRule ^about$ /widgets.html [L]

I intentionally wrote this example without anchors because it wasn't clear whether he's using a subdirectory and I didn't want to get into further detours. And, ahem, the displaced directory slash in my quoted rule was a typo on your part, unless the moderators sneaked in and fixed an unnoticed typo in my original post.

if ($_GET['page'] == ''){
$pg='home';
}
else {
$pg=($_GET['page']);
}

As we all know, I only speak three words of php so I say this with hesitation, but wouldn't it be safer if the condition said something like
if (empty($_GET['page']))
?
or (not sure about php versions here)
$somevariable = $_GET['page']
followed by
if (empty($somevariable))


nevski, we are taking a little bit of a detour to ensure that you get the whole rewrite concept clear. We are temporarily not thinking about your "real" about/contact/legal/etc. pages at all, but just rewriting to some randomly chosen static page. So when we say "widgets.html" we mean some page that really exists on your WAMP site. Pick one and use it. Or just throw together a page that says
<html>
<head>
<title>The Widget Page</title>
</head>
<body>
This is a fake page!
</body>
</html
and use that. (It does not have to validate, your browser just has to be able to open it ;))
nevski



 
Msg#: 4595719 posted 11:32 pm on Jul 27, 2013 (gmt 0)

Yes of course,no problem I understood that it is about basic pages,for the test purpose.I just wrote the structure of my page,maybe because of it the rule doens't work.

This structure of page I use mainly because it is cleaner and easier to manipulate that's all.

I'm working on my project that would be full of variables and all kind of things.So if I don't learn mod_rewrite the website itself would not be exploited in proper way.

I must admit that I thought that rewriting would be easier.But that is not case for me.It takes time to learn it properly and I know that,I'm patient,sometimes angry,but all this is part of study process.

I decided to first of all learn syntax in proper way because IMO it is foundation of the mod_rewriting house )))

So we will take a break with real programing classes,and I will ask you some questions about syntax...

Cheers guys))

nevski



 
Msg#: 4595719 posted 11:50 pm on Jul 27, 2013 (gmt 0)

My first question from glossary is

. (a dot) matches any single character, except the ending of a line.

\ is called an escaping character, this removes the function from a 'special character' (EG if you needed to match index.php?, which has both a . (dot) and a ?, you would have to 'escape' the special characters . (dot) and ? with a \ to remove their 'special' value it looks like this: index\.php\?)


^index\.php$

^-in this part of code it represents beggining of a line
$-is represents wnd of line,and also matches variabiles from pattern to substitution.

Ok so one explenation is needed

\. First of all dot here represents part of mod_rewrite syntax or represents same dot, as in .jpeg,.png.

. (a dot) matches any single character, except the ending of a line.

\ is called an escaping character, this removes the function from a 'special character' (EG if you needed to match index.php?, which has both a . (dot) and a ?, you would have to 'escape' the special characters . (dot) and ? with a \ to remove their 'special' value it looks like this: index\.php\?)

in upper case it removes dot(.) after index.But what is about php?Does php that stays for matching?What happened to it?
Or it says that all url's that have index and php would be matched?It confuses me a lot.

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4595719 posted 11:56 pm on Jul 27, 2013 (gmt 0)

I must admit that I thought that rewriting would be easier.

It's like tying your shoelaces. Once you know how to do it you don't even need to think about it. Unless, ahem, you delete one RewriteCond because you think it's no longer needed, and then you find the next day's logs overflowing with redirects. But have you ever had to teach someone how to tie their shoes? Let alone explain it in words...

Edit because I missed your second post:

In a regular expression,
index.php

could match:
index.php
indexaphp
index/php
index3php

et cetera. It would also match "index php" but in an URL this won't occur.

But
index\.php

only matches
index.php

The "escape" means that the next character is the literal character --in this case a . period-- instead of whatever special meaning it might have as a Regular Expression.

Similarly:
[^a]
means "any character that is not the letter 'a'"
but
[\^a]
means "any character that is either the letter 'a' or a literal ^ caret".

a$
means "the letter 'a' if it occurs at the very end of your text"
but
a\$
means "the sequence 'a$' anywhere in the text"

a?
means "there may or may not be one letter 'a' here"
but
a\?
means "the sequence 'a?'"

Further edit:
Just to confuse you, many symbols have more than one meaning in Regular Expressions, depending on where they are used. In particular:

$ in a pattern means "the very end of the string you're looking at"
$ in a target or replacement has to be followed by a number, and now it means "the first (second, third etc.) thing that you captured". In the RewriteRules we're currently working on, there is only one capture, so it's $1

^ (only used in a pattern) means "the very beginning of the string"
unless it is the first character inside grouping brackets, when it means "not"

And, to confuse you still further:
Some symbols are basic to Regular Expressions. They mean the same thing everywhere. Others depend on what language is using the Regular Expression.

In mod_rewrite, / doesn't mean anything. It's just another character. But in some languages-- and even some Apache modules-- the /slash/ is used to mark the beginning and end of a Regular Expression. So if you're searching for text that contains a literal / slash, it has to be escaped: \/

In ordinary regular expressions, a space " " is just another character. But in Apache, a space by itself has meaning; it's like punctuation. So if you need to find a literal space in mod_rewrite-- for example looking at a request string "GET /about HTTP/1.1" --you have to "escape" the space:
GET\ /about\ HTTP/1\.1

[edited by: lucy24 at 12:12 am (utc) on Jul 28, 2013]

nevski



 
Msg#: 4595719 posted 12:10 am on Jul 28, 2013 (gmt 0)

So actually it this case is \. needed to escape threating .php extension as part of mod_rewrite syntax where .(dot has meaning).

Also here

RewriteCond %{THE_REQUEST} \?

\ is used to tell to mod_rewite to escape from

index.php?page=variable

and just to take page=variable right?

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4595719 posted 12:12 am on Jul 28, 2013 (gmt 0)

RewriteCond %{THE_REQUEST} \?

The condition matches if
THE_REQUEST contains a literal question mark.

THE_REQUEST is the literal HTTP request sent by the browser:

GET / HTTP/1.1
GET /about HTTP/1.1
GET /about.html HTTP/1.1
GET /index.php HTTP/1.1
GET /index.php?page=about HTTP/1.1

The RewriteRule RegEx pattern attempts to match the path part of this request.

If it matches, then any RewriteConds are assessed.

A RewriteCond can test the whole lot by looking at THE_REQUEST, just the QUERY_STRING part, or various other things.

If everything matches, the Rule and all Conditions, then the rule target is invoked.

[edited by: g1smd at 12:23 am (utc) on Jul 28, 2013]

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4595719 posted 12:13 am on Jul 28, 2013 (gmt 0)

Oops, we've overlapped. In fact I added the part about ? while you were typing, so take a minute to re-read.

nevski



 
Msg#: 4595719 posted 12:19 am on Jul 28, 2013 (gmt 0)

Tnx Lucy24,no problem I get it now... \ says take naxt elememt . or ? as literal not as par of apache mod_rewrite syntax.

You know you talked about happiness this is the feeling right now)))I finally get something)))

One off topic question.Does this forum has EDIT previous post section?I was trying to find it but wothout success(((

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4595719 posted 12:25 am on Jul 28, 2013 (gmt 0)

The "owner edit" button (under your username) allows post editing. There is a time limit.

nevski



 
Msg#: 4595719 posted 12:39 am on Jul 28, 2013 (gmt 0)

RewriteCond %{THE_REQUEST} \? this is understood tnx
RewriteCond %{QUERY_STRING} page=([a-z]+)

This is for capturing strings which name we decide in this case page.Right?
and finaly [a-z]+ says catch these small letter 1 or more time,so without a if there is variable for example ananas,it would not be matched because there are 3 a in it,and with that + it says keep matching?

I'm really happy))))

When I finish some my projets I would put,a link or banner of your site/forum on it for sure)))

nevski



 
Msg#: 4595719 posted 10:50 am on Jul 28, 2013 (gmt 0)

RewriteEngine on
RewriteCond %{THE_REQUEST} \?
RewriteCond %{QUERY_STRING} page=([a-z]+)
RewriteRule ^index\.php$ http://localhost/%1? [R=301,L]

RewriteRule ^about$ /widgets.html [L]
RewriteCond %{THE_REQUEST} [A-Z]{3,9}\ /widgets\.html\ HTTP/
RewriteRule ^widgets\.html$ http
://localhost/about [R=301,L]

I've tryied to analize this code,but there is a problem.
My widget.html file has place alongisde index.html.

RewriteRule ^about$ /widgets.html

This rule says ok look for matching with about and then rewrite it to widgets.html,as I understood,is this right?

RewriteCond %{THE_REQUEST} [A-Z]{3,9}\ /widgets\.html\ HTTP/

I understand partly this condition,what it says?

RewriteRule ^about$ /widgets.html [L]
This says match about in the request and rewrite it to file widgets.html or in the other example is would be /index.php?page=$1

Finally RewriteRule ^widgets\.html$ localhost/about [R=301,L]

Says look for widgets.html to match and redirect it to localhost/about

I get error 404,object not found in this example or in the other.When I type it manualy localhost/root_folder/widgets.html it works well and it redirects it to localhost/about,but it doesn't load the content,just shows error 404.What problem it could be?

[edited by: phranque at 5:27 pm (utc) on Jul 30, 2013]
[edit reason] unlinked urls [/edit]

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4595719 posted 11:22 am on Jul 28, 2013 (gmt 0)

FORGET ABOUT LOCALHOST.

Uhm. Sorry. Didn't mean to shout.

For present purposes, within WAMP, you do not need to give a hostname. Ever. Just be sure that any rule that is intended as a redirect has the full [R=301,L] flag.

This is a special pattern that applies only to local testing (MAMP, WAMP, whatever-the-###-it-is-in-linux). All targets will look exactly the same: leading / representing the root, and then the rest of the URL. No difference between redirect and rewrite. Only the flags will be different. (Even on your live site, targets in this form would still work with redirects, so long as you use the right flag. But we'll get into that later.)

When I type it manualy localhost/root_folder/widgets.html it works well

Oh, for heaven's sake. If the URL of your "widgets.html" file is
/root_folder/widgets.html
then that is what you have to say in any targets. And, conversely, in a pattern it would have to be
^root_folder/widgets.html
or else
widgets.html with no anchor. But we haven't got to that part yet.

nevski



 
Msg#: 4595719 posted 11:54 am on Jul 28, 2013 (gmt 0)

SHOOUT freely if it helps to get things)))

The thing that confuses me is that

in this rule

RewriteEngine on
RewriteCond %{THE_REQUEST} \?
RewriteCond %{QUERY_STRING} page=([a-z]+)
RewriteRule ^index\.php$ /%1? [R=301,L]

when I click on the link it says:

localhost:1337/about
Connection failed
Firefox can't establish connection with server

It only shows disired URL when I type localhost/%1? in the url.Then it shows 404error.

I'm using XAMPP on Windows...

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4595719 posted 6:27 pm on Jul 28, 2013 (gmt 0)

When you type "localhost" here in the forum, do you mean
http://localhost/ ?
nevski



 
Msg#: 4595719 posted 7:00 pm on Jul 28, 2013 (gmt 0)

No,no,just I had that problem that only when I write in the code http://localhost/blalala it showes the right thing,the desired url redirect,and when I write localhost,or localhost/%1?,or only /%1? it says can't esablish connection with server,no errors like 404 or 500 etc...

This is shown in address bar...

localhost:1337/about
Connection failed
Firefox can't establish connection with server


I even tried as Lucy24 sugested to do:

There's another thing you can do on your local WAMP. First shut down the server and make a copy of the config file. Now EDIT the config file-- the real one, not the copy-- to add a RewriteLog:
RewriteLog /logs/rewrite.log
RewriteLogLevel 9
Restart the server and continue testing. But if mod_rewrite already makes you anxious, logging rewrites may not make you any happier.


But after doing this and enetering RewriteLog in the file Apache didn't worked,so I returned backup file...

What can cause this problem?

[edited by: phranque at 5:29 pm (utc) on Jul 30, 2013]
[edit reason] unlinked url [/edit]

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4595719 posted 9:41 pm on Jul 28, 2013 (gmt 0)

I had that problem that only when I write in the code http://localhost/blalala

That's why I keep saying: DON'T write "localhost" in the code. Start with the directory slash.

By default / means "start from the root of whatever host you are currently in". There are not many things that mean exactly the same thing in mod_rewrite and in the body of an html page-- but this is one of them.

Comment-out all RewriteRules and RewriteCond in XAMPP. Leave only the line
RewriteEngine On

Now put in this one line:

RewriteRule about /root_folder/widgets.html [R=301,L]

replacing "root_folder/widgets.html" with the URL of some static html file that physically exists in your XAMPP site.

Open your local site in the browser. Now edit the address bar so the path of the URL includes the string "about".

Do you end up on the "widgets.html" page? Address bar and page content should both say so.

Now edit your htaccess to delete the R=301 but keep the L.

Again, request some local page with "about" in the name. You may need to refresh the browser window and maybe even empty the cache.

Do you see the content of "widgets.html" while the address bar still says whatever you typed?

:: wandering off to test RewriteLog for myself ::

Edit: Well, that will teach you to take my advice. #1 It has to be in quotation marks, and #2 On my system it refuses to create a log file unless I give the full filepath beginning /Applications/MAMP/ et cetera. (Option 2, leaving off the slash before /logs/, doesn't work.)

And that's why we have MAMP ;)

[edited by: lucy24 at 10:09 pm (utc) on Jul 28, 2013]

nevski



 
Msg#: 4595719 posted 10:05 pm on Jul 28, 2013 (gmt 0)

Nope I don't get it,it redirects in browser adress bar when I type about,but he doesn't load the page.

Is says like on this photo

[support.cdn.mozilla.net...]

Firefox can not establish a connection to server localhost:1337
This is my rule
RewriteEngine on
RewriteRule about /testing/widgets.html [R=301,L]

All other rules are deactivated by #,cache is empty...

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4595719 posted 10:13 pm on Jul 28, 2013 (gmt 0)

I Am Mystified.

While you were typing I was hammering away at the RewriteLog. I have done something wrong somewhere, because the MySQL server refuses to start, but at least it is finally logging rewrites as intended.

The good news is: The problem is not in the RewriteRule. That is working exactly as intended.

If you try the next version-- deleting the R=301 flag --do you get the same error message again, only with no change in address bar?

nevski



 
Msg#: 4595719 posted 10:31 pm on Jul 28, 2013 (gmt 0)

Now all is ok with [L] it opens the page without changing it in the url bar.No errors,everything works as expected,only with R=301 there is problem.

Now on address bar it writes normal localhost without localhost:1337 or so.

nevski



 
Msg#: 4595719 posted 10:41 am on Jul 29, 2013 (gmt 0)

I'm confused right now since with [L] page loads as it should be,and with same code with but flags[R=301,L] it says can't establish connection with server...

Also I downloaded newest version of Xampp...still,nothing changes.

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4595719 posted 4:27 pm on Jul 29, 2013 (gmt 0)

Now on address bar it writes normal localhost without localhost:1337 or so.

Uh-oh, wait, this may be bad. I don't know about your setup, but on mine, "localhost" alone is what I see when I've opened an html document straight from the desktop, without going through the server.

If you replace the static HTML target with a dynamic page-- either php or something that uses SSIs --does the whole thing display as intended?

nevski



 
Msg#: 4595719 posted 4:44 pm on Jul 29, 2013 (gmt 0)

Now I checked,opened widgets.html from root folder,just double click and on the address bar of browser is

file:///C:/xampp/htdocs/testing/widgets.html -when static

same case as dynamic

file:///C:/xampp/htdocs/testing/widgets.php

Same case on desktop or with different browsers Chrome,Mozzila,IE...

I've finally changed to widgets.php when rule is with [L] flag it works.

When [R=301] is the case it still shows

http://localhost:1337/testing/widgets.php

and can't establish connection with server localhost:1337

Is it worth of shot to try it on the web on test server?

I've tested it on web testing server,the rule works as charm

RewriteEngine on
RewriteBase /
RewriteRule about /widgets.php [R=301,L]


I'm really confused with localhost,it pretty important since the most of testing should be on localhost...

YYYYYYYYYYYYYEEEEEEEEY GUYS both R=301 an L are working on my test site even with variables!You are the best!
[snip] -this is the address of my test site))))

I started to lose hope,that something will work,now I have huge boost for mod_rewrite study)))Ynx to YOU all!

[edited by: phranque at 5:24 pm (utc) on Jul 30, 2013]
[edit reason] no personal urls please [/edit]

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4595719 posted 7:41 am on Jul 30, 2013 (gmt 0)

Let's see the final code to check for any issues that have been missed.

Add a blank line after each RewriteRule.

nevski



 
Msg#: 4595719 posted 9:48 am on Jul 30, 2013 (gmt 0)

RewriteEngine on
RewriteBase /(this is only for on-line server testing)
RewriteCond %{THE_REQUEST} \?
RewriteCond %{QUERY_STRING} page=([a-z]+)
RewriteRule ^index\.php$ /%1? [R=301,L]
RewriteRule ^([a-z]+)$ /index.php?page=$1 [L]


This is the code,and no matter if there is widgets.html,witdgets.php or in this case passing variable result on localhost is the same it says:

Can't establish connection with server

Firefox can not establish a connection to server localhost:1337

So on the browser address bar(every of 3 browsers that I have) with R=301 it does redirect as intended,but it can't establish connection with a server...on testing webserver it does everything as intended.

I've checked if AllowOverride is set to All,and is there some kind of thing in configuring Apache itself must be done?

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4595719 posted 9:55 pm on Jul 30, 2013 (gmt 0)

This is definitely weird. The good news is that there is nothing wrong with your RewriteRule, so you can stop worrying about that. The bad news is that there is nothing wrong with your RewriteRule, so we are now dealing with a deeper WAMP problem. (Or was it XAMP? There are two concurrent threads...)

How do you get to your local pages in the first place? Can you type an URL in the address bar? Can you click links within your site's pages? (ONLY IF site-internal links begin with something other than http)

Does the config file and/or htaccess say
Options +FollowSymLinks
?
As I understand it, leaving out this rule won't prevent a redirect from happening, but it may send the redirect to the wrong place. But frankly the whole thing makes no sense. Obviously your browser has made contact with the server, or you wouldn't be on the page in the first place. We may need to find someone who uses your exact _AMP variant; it's not an error I can ever remember getting in MAMP.

nevski



 
Msg#: 4595719 posted 11:19 pm on Jul 30, 2013 (gmt 0)

First of all I'm using the Xampp version 3.2.1.I've substituted the older version of Xampp because I though that the older version causes the problem,but the problem remained.

To access the website on my localhost I just type localhost/folder(that contains the website)/ and without problems it loads the page.Links are loaded normally also.

When in rewrite rule is only flag L the pages load normaly,like when I type name other page that I have in rewrite rule.

The problem beggins wih R=301 flag it redirects the page and says connection with localhost:blahbalh can't be established.No matter what is written in substitution (localhost/%1?,or only /%1?).Only when i write http://localhost/%1? it normaly shows it in address bar like localhost/%1? but with 404error...

I didn't put +FollowSymLinks in any of mine .htaccess files...

[edited by: phranque at 11:31 pm (utc) on Jul 30, 2013]
[edit reason] unlinked url [/edit]

This 117 message thread spans 4 pages: < < 117 ( 1 [2] 3 4 > >
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved