Forum Moderators: phranque

Message Too Old, No Replies

PHP rewrite not working

Did I do it right?

         

wheelie34

6:25 pm on May 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Taken on a new client and been setting up the site, canonical etc making sure one result is returned for a page.

I have the non www to www in place but am having problems with the 2 following for some reason on this server.

RewriteCond %{HTTP_HOST} ^example\.org/index.php [NC]
RewriteRule (.*) http://www.example.org/index.php$1 [R=301,L]

The above doesn't go to index.php, only if the / is used, I have a 301 from non www example\.ork? to with www .org/index.php which works fine there?

RewriteRule ^?c=111&s=444$ http://www.example.org.uk/index.php?c=111&s=444? [R=301,L]

The above creates a server error and doesn't allow pages to load? how close am I? help with the above 2 problems would be welcome, thanks

g1smd

7:38 pm on May 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What is it meant to do?

What does it actually do?

Document that more clearly and I might have a solution.

.

The HTTP_HOST item cannot include any folder names, only a domain name.

I will also point out that it is usually a bad idea to include the index file filename in a link. The canonical URL for index files usually ends with a trailing / on the end of the URL.

wheelie34

7:57 pm on May 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi

If someone types in example.org/index.php I want it to redirect to www.example.org/index.php BUT I now see your point about folder level and apache auto adding the /

This one

RewriteRule ^?c=111&s=444$ http://www.example.org.uk/index.php?c=111&s=444? [R=301,L]

From a search result page, whoever set it up didnt put index.php in front of the?c= string so the site has ended up with www.example.org/index.php?c=111 AND www.example.org/?c=111 so I fixed the script and just want to 301 the?c=111 to index.php?c=111 as its already indexed by the engines.

Thanks for the help so far

jdMorgan

2:56 am on May 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds like there are errors on top of errors...

HTTP_HOST contains the requested hostname (domain name) and an optional port number, e.g. "www.WebmasterWorld.com:80" for HTTP/1.1 requests. It will be blank if the request is a true HTTP/1.0 request, but then, true HTTP/1.0 requests cannot be used to reach name-based virtual servers, so this is not usually a big concern.

The URL-path examined by RewriteRule is only the local URL-path, stripped of any path info leading to the directory in which the RewriteRule resides. It contains no query string data, only the local URL-path.

QUERY_STRING contains the query string if any, and RewriteCond can be used to test it and back-reference all or part(s) of it.

The query string can be replaced by RewriteRule if you wish, or you can clear the query string by appending a "?" to the substitution URL or URL-path. If you do neither, the query string will be passed through mod_rewrite unchanged.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

wheelie34

7:13 am on May 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks fellas, g1smd your sticky mail is full, I got the file thanks.