Forum Moderators: phranque
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
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.
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
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