This is my first time trying to write htaccess rules. My target is to make all relative links to be redirected to absolute. To begin i was testing:
RewriteEngine On
RewriteRule gallery\.php$ http://www.domain.com/sample/gallery.php
RewriteRule info\.php$ http://www.domain.com/sample/gallery.php
The first rule makes Firefox throw the error "The page isn't redirecting properly" when I click on the link, while the second rule works fine. The idea for the future was to write a rule like,
RewriteRule catchAllRelativeLinks$ http: //www.domain.com/sample/$1
but if I can't make the first rule work I don't think I will find how to make the real rule.
EDIT: to avoid the endless loop can't i try to understand if i am on the first or second istance by catching a variable ? some ideas i tried (and faild):
RewriteCond %{IS_SUBREQ} false
RewriteRule ^gallery\.php$ http://www.domain.com/gallery.php?a [R=302,L]
RewriteCond %{THE_REQUEST} !(\?something)$
RewriteRule ^gallery\.php$ http://www.domain.com/gallery.php?something [R=302,L]
or with an environment variable,
thanks again
The first rule you have results in an endless loop. mod_rewrite
isn't all that great at making relative links absolute. That should be done in the HTML. For example, turning
<a href="gallery.php">Gallery</a>
into
<a href="/sample/gallery.php">Gallery</a>
However, the second rule works because it does something mod_rewrite
does extremely well, and that's redirecting from one page or URL to another. For more information on this please see, the Apache documentation .
You can checkout this link for detailed explanation.
https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
This worked for me (:
RewriteEngine on # Check for POST Submission | # Because POST parameters aren't retained on a redirect. # You can omit that line if you want to make sure that all POST submissions are secure # (any unsecured POST submissions will be ignored) RewriteCond %{REQUEST_METHOD} !^POST$ # Forcing HTTPS RewriteCond %{HTTPS} !=on [OR] RewriteCond %{SERVER_PORT} 80 # Pages to Apply RewriteCond %{REQUEST_URI} ^something_secure [OR] RewriteCond %{REQUEST_URI} ^something_else_secure RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.