I need to create a rule for all GET requests to my site so that:
GET /articles/topic1.html?showall=1
is rewritten as:
GET /articles/topic1.html
I have the following .htaccess file on my Joomla site:
RewriteEngine On
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]
########## This is the Rule I have added ################
RewriteRule ^(.*)$ /$showall=1 [R=301,L]
RewriteBase /
I have added comments on the line that I have added. Unfortunately it doesn't work, the browser warns me I have generated a circular loop....
Any idea how to fix it ??
Thanks
Frank
Try replacing that with:
RewriteCond %{QUERY_STRING} ^showall=([0-9])+$
RewriteRule ^articles/topic[0-9]*\.html /articles/topic%1.html? [L]
Or if it's really topic1.html, then you want this:
RewriteCond %{QUERY_STRING} ^showall=1$
RewriteRule ^articles/topic1\.html /articles/topic1.html? [L]
Related
i have this link
http://localhost/fukhtaccess
and i want redirect the link to http://server.localhost/index.php with GET params.
this is my htaccess, but don't work and not possibile test with some error for debug (thanks apache foundation!!!)
RewriteEngine On
RewriteCond %{HTT_HOST} ^localhost$
RewriteCond %{REQUEST_URI} fukhtaccess
RewriteRule (.*) http://server.localhost/index.php [QSA,L]
You have a typo: change HTT_HOST to HTTP_HOST.
Also, your second RewriteCond just complicates things unnecessarily. Do this instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule fukhtaccess http://server.localhost/index.php [QSA,L]
better, this work fine
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost [NC]
RewriteCond %{REQUEST_URI} fukhtaccess$ [NC]
RewriteRule (.*) http://server.localhost/index.php [QSA,L]
There are some URLs with the same URL structure pattern:
//www.example.com/index.php?hop=this&step=that&fgh=1001
//www.example.com/index.php?hop=this&step=that&fgh=1002
//www.example.com/index.php?hop=this&step=that&fgh=1003
The //www.example.com/index.php?hop=this&step=that&fgh= part is the same.
1001~1003 is the only unique part.
I want to change/redirect them to:
http://www.example.com/fgh/1001
http://www.example.com/fgh/1002
http://www.example.com/fgh/1003
This site runs on Apache with mod_rewrite.
I have tried working on the .htaccess file to rewrite the rule, but failed so far.
I hope anyone can help me to rewrite the code in .htaccess
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index\.php\?hop=this&step=that&fgh=(\d+) [NC]
RewriteRule ^ /fgh/%1? [R=301,L]
RewriteRule ^fgh/(\d+)/?$ index.php?hop=this&step=that&fgh=$1 [QSA,L,NC]
Keep these 2 rules just below RewriteEngine line.
It should work for you. I dint check it out.
Put it in .htaccess
RewriteEngine On
RewriteCond %{QUERY_STRING} ^hop=(.*)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^step=(.*)$ [NC,OR]
RewriteRule (.*) /$1? [R=301,L]
RewriteRule index/fgh/(.*)/ index.php?fgh=$3
RewriteRule index/fgh/(.*) index.php?fgh=$3
Let me add main part of my .htaccess file;
RewriteEngine On
RewriteRule index\.php - [L]
#This is the code I tried but not working
RewriteCond %{QUERY_STRING} ^hop=this&step=that&fgh=([^&]+)$ [NC]
RewriteRule ^(index\.php)?$ /fgh/%1? [R=301,L,NC]
## End of deny access to extension xml files
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
I am trying to use SSL on my website, but the recources that have a relative URL load as http:// even when the page is using https://
This is my .htacces
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)=http [NC]
RewriteRule ^(.*)$ – [F,L]
RewriteCond %{http_host} ^tacticalghillies.nl [NC]
RewriteRule ^(.*)$ http://www.tacticalghillies.nl/$1 [L,R=301]
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
What am I screwing up?
Difficult to understand all your "code".
I think you can add in the beginning :
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]
Rather than mess with HTACCESS (you can easily screw up your SEF URLS is you do) just use the Joomla global configuration and force SSL to always on. Any Joomla page will automatically use SSL if you turn on the setting.
I'm trying to rewrite some legacy Joomla URLs on a site that's now using ExpressionEngine as its CMS but they're not working.
The ExpressionEngine URL rewrites, i.e. removing index.php from the URL work fine though.
This is what I've got:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
# This is the one that's not working
RewriteRule /index.php?option=com_chronocontact&Itemid=54 /contact/ [R=301,L]
# Force www
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} (.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# Redirect index.php Requests
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteCond %{THE_REQUEST} ^GET
RewriteRule ^index\.php(.+) $1 [R=301,L]
# Standard ExpressionEngine Rewrite
RewriteCond %{REQUEST_URI} ^/
RewriteCond %{QUERY_STRING} ^(gclid=.*)
RewriteRule ^(.+) /index.php?/ [L,PT]
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(assets|css|images|tinymce|js|min|cms|themes|index\.php|admin\.php|favicon\.ico|index\.php|path\.php|php\.ini) [NC]
RewriteRule ^(.+) /index.php?/ [L]
</IfModule>
Can anyone spot what I'm doing wrong?
The first thing is the stray RewriteCond %{HTTPS} !=on that you have at the top. It looks like it belongs to the rule under it, as in:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} (.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
As far as the rule that you have commented that doesn't work, the ? is a reserved character for regular expressions, and your pattern actually says that the second p in /index.php is "optional". Additionally, you can't match against the query string in a rewrite rule, you need to use a rewrite condition and match against the %{QUERY_STRING} variable:
RewriteCond %{QUERY_STRING} ^option=com_chronocontact&Itemid=54$
RewriteRule ^(index.php)?$ /contact/? [R=301,L]
is probably more along the lines of what you're looking for.
I have the following rules in my httpd.conf
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} password=*
RewriteCond %{QUERY_STRING} bi2=(.*)
RewriteCond %{REQUEST_URI} /myGet.php(.*)$
RewriteRule ^(.*)$ http://blog.myexample%1.com/$1
However, when I executed the Request URI
/myGet.php?password=john&bi2=67
I was redirected to
http://blog.myexample.com/myGet.php?password=john&bi2=67
instead of
http://blog.myexample67.com/myGet.php?password=john&bi2=67
It seems that %N for the RewriteCond BackReferencing is not working. Although $N is.
Alter the order or the RewriteCond directives so that the last directive is the one you want the information from:
RewriteCond %{QUERY_STRING} password=*
RewriteCond %{REQUEST_URI} /myGet.php(.*)$
RewriteCond %{QUERY_STRING} bi2=(.*)
RewriteRule ^(.*)$ http://blog.myexample%1.com/$1
But I rather suggest:
RewriteCond %{QUERY_STRING} password=
RewriteCond %{QUERY_STRING} bi2=([^&]*)
RewriteRule ^/myGet\.php.*$ http://blog.myexample%1.com$0