Remove trailing slash after domain - apache

This is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Remove multiple slashes anywhere in URL
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
# Never use www prefix!
RewriteCond %{HTTP_HOST} ^www.domain\.org [NC]
RewriteRule (.*) http://domain.org/$1 [R=301,L]
# Remove multiple slashes after domain
RewriteRule ^/(.*)$ http://domain.org/$1 [R=301,L]
# Remove trailing slash in some cases
RewriteRule ^(.*)\.css/$ http://domain.org/$1.css [L,R=301]
RewriteRule ^(.*)\.js/$ http://domain.org/$1.js [L,R=301]
RewriteRule ^(.*)\.jpg/$ http://domain.org/$1.jpg [L,R=301]
RewriteRule ^(.*)\.jpeg/$ http://domain.org/$1.jpeg [L,R=301]
RewriteRule ^(.*)\.png/$ http://domain.org/$1.png [L,R=301]
RewriteRule ^(.*)\.gif/$ http://domain.org/$1.gif [L,R=301]
RewriteRule ^(.*)\.xml/$ http://domain.org/$1.xml [L,R=301]
# Force trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)\.css
RewriteCond %{REQUEST_URI} !(.*)\.js
RewriteCond %{REQUEST_URI} !(.*)\.jpg
RewriteCond %{REQUEST_URI} !(.*)\.jpeg
RewriteCond %{REQUEST_URI} !(.*)\.png
RewriteCond %{REQUEST_URI} !(.*)\.gif
RewriteCond %{REQUEST_URI} !(.*)\.xml
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://mydomain.org/$1/ [L,R=301]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
# MIME types
AddType text/css .css
AddType text/javascript .js
# Enable compression
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/x-css text/x-javascript text/x-js text/htm application/x-javascript application/javascript application/js application/x-js image/png image/gif image/jpg image/jpeg
#Skip browsers with known problems
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
php_flag display_errors on
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
But, when I go to **/////, the trailing slashes will not go away. What am I doing wrong?

The %{REQUEST_URI} variable gets reduced of extra slashes when it gets prepped. So the condition RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ will never match because for a request like http://domain.org////, the REQUEST_URI variable gets reduced to just /. Try using the THE_REQUEST variable:
RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})\ (.*)//([^\ ]*)
RewriteRule ^ %2/%3 [R=301,L]
Additionally, the prefix (the leading slash) gets stripped off of the request URI when rewrite rules are in an htaccess file, so the rule RewriteRule . %1/%2 [R=301,L] would never match because the regex . requires at least one character to match. When the URI is / and the leading slash gets stripped, the URI that's used to match in the url is a blank string. So using ^, or (.*), or something equivalent of "everything including nothing" regex needs to be used.

Related

410 redirect working for index.html but not for index.php

I have the following folder structure:
~ $ ls -1a ./html/.htaccess ./html/brochure_en/
./html/.htaccess
./html/brochure_en/:
.
..
index.html
index.php
The content of the .htaccess file is:
~ $ cat ./html/.htaccess
Redirect 410 /brochure_en/index.php
Redirect 410 /brochure_en/index.html
The line for "index.html" works, but access to "index.php" still returns http status code 200. Is this something the webserver admin has to fix or do I have to change something in the .htaccess file?
Thanks
UPDATE: Below is the full .htaccess file. I just replaced some strings, e.g. sed 's/mycompany/example/g'. Below .htaccess is in the webroot folder. There are other .htaccess files. But those don't affect the folder /brochure/ and its content, because they are in other folder, e.g. /de/, /en/.
Require all granted
AddDefaultCharset utf-8
AddType application/javascript .js
AddType application/json .json
AddType font/woff .woff
AddType font/woff2 .woff2
AddType image/gif .gif
AddType image/jpeg .jpg
AddType image/png .png
AddType image/svg+xml .svg
AddType image/x-icon .ico
AddType text/css .css
AddType text/html .html
AddType text/plain .txt
AddType text/xml .xml
AddType video/mp4 .mp4
AddType video/webm .webm
Header set Cache-Control "max-age=604800, public, no-transform"
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Content-Security-Policy "base-uri 'self'; default-src 'none'; form-action 'none'; frame-ancestors 'none';"
Header always set X-Content-Security-Policy "base-uri 'self'; default-src 'none'; form-action 'none'; frame-ancestors 'none';"
Header always set X-WebKit-CSP "base-uri 'self'; default-src 'none'; form-action 'none'; frame-ancestors 'none';"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" "expr=%{HTTPS} == 'on'"
Header always unset Public-Key-Pins
Header always unset Public-Key-Pins-Report-Only
Header always unset Cookie
Header always unset Set-Cookie
Options -ExecCGI -FollowSymlinks -Includes -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]
RewriteCond %{SERVER_NAME} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteRule ^(|/)\. - [F]
RewriteRule ~$ - [F]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP:Accept-Language} ^de.*$ [NC]
RewriteRule ^(.*)$ https://www.example.com/de/ [R=302,L]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://www.example.com/en/ [R=302,L]
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ /$1? [R=301,L]
RewriteRule ^(.*)/index\.html$ $1/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/de/(behandlungskonzept|kontakt-und-info|exampletherapie|produkte)/$ [NC]
RewriteRule ^(.*)$ https://www.example.com/de/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/(contact-and-info|example-therapy|products|treatment-concept)/$ [NC]
RewriteRule ^(.*)$ https://www.example.com/en/ [R=301,L]
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>> REDIRECT OBSOLETE URLS >>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>> FALSE GOOGLE ENTRIES
RewriteCond %{REQUEST_URI} ^/35 [NC,OR]
RewriteCond %{REQUEST_URI} ^/45 [NC]
RewriteRule ^(.*)$ https://www.example.com/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/brochure_de/docs/brochure_de\.pdf [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/willkommen/14-german-de-ch-at/support/59-dokumentation [NC]
RewriteRule ^(.*)$ https://www.example.com/de/ [R=301,L]
#<< FALSE GOOGLE ENTRIES
RewriteCond %{REQUEST_URI} ^/de/allgemeine-geschaeftsbedingungen-und-kundeninformation [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/entsorgung-von-altbatterien [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/hinweis-zur-entsorgung-von-altbatterien [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/rechtstexte [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/anwendungsbereiche/gesetzliche-vorschriften [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/geschaeftspartner/forschung [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/geschaeftspartner/medizin [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/geschaeftspartner/vertrieb [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/sitemap [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/support/software [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/unternehmen/philosophie [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/unternehmen/standort [NC]
RewriteRule ^(.*)$ https://www.example.com/de/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/de/produkte/exampleyair-example [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/produkte/example-example [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/produkte/example-example [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/produkte/example-example [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/produkte/example-examplep [NC]
RewriteRule ^(.*)$ https://www.example.com/de/produkte/behandlungsgeraete/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/de/anwendungsbereiche/exampletherapie [NC]
RewriteRule ^(.*)$ https://www.example.com/de/exampletherapie/example-und-example/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/de/anwendungsbereiche/kontraindikation [NC,OR]
RewriteCond %{REQUEST_URI} ^/de/anwendungsbereiche/offene-und-geschlossene-systeme [NC]
RewriteRule ^(.*)$ https://www.example.com/de/exampletherapie/kontraindikation/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/de/anwendungsbereiche/zahnmedizin [NC]
RewriteRule ^(.*)$ https://www.example.com/de/exampletherapie/indikation/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/de/unternehmen/kontakt [NC]
RewriteRule ^(.*)$ https://www.example.com/de/kontakt-und-info/kontaktformular/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/de/support/medien [NC]
RewriteRule ^(.*)$ https://www.example.com/de/kontakt-und-info/produktvideos/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/de/impressum [NC]
RewriteRule ^(.*)$ https://www.example.com/de/kontakt-und-info/impressum/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/de/datenschutzerklaerung [NC]
RewriteRule ^(.*)$ https://www.example.com/de/kontakt-und-info/datenschutzerklaerung/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/application-area/statutory-provisions [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/business-partner/medicine [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/business-partner/distribution [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/business-partner/research [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/sitemap [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/company/location [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/company/philosophy [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/support/software [NC]
RewriteRule ^(.*)$ https://www.example.com/en/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/products/exampleyair-example [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/products/example-example [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/products/example-example [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/products/example-example [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/products/example-examplep [NC]
RewriteRule ^(.*)$ https://www.example.com/en/products/treatment-devices/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/application-area/example-therapy [NC]
RewriteRule ^(.*)$ https://www.example.com/en/example-therapy/example-and-examplee/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/application-area/contraindication [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/application-area/open-and-closed-systems [NC]
RewriteRule ^(.*)$ https://www.example.com/en/example-therapy/contraindication/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/application-area/dentistry [NC]
RewriteRule ^(.*)$ https://www.example.com/en/example-therapy/indication/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/company/contact [NC]
RewriteRule ^(.*)$ https://www.example.com/en/contact-and-info/contact-form/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/support/media [NC]
RewriteRule ^(.*)$ https://www.example.com/en/contact-and-info/product-videos/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/company-information [NC]
RewriteRule ^(.*)$ https://www.example.com/en/contact-and-info/legal-notice/ [R=301,L]
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#<< REDIRECT OBSOLETE URLS <<<
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#<<<<<<<<<<<<<<<<<<<<<<<
#<< DELETE BAD LINKS <<<
#<<<<<<<<<<<<<<<<<<<<<<<
Redirect 410 /brochure_de
Redirect 410 /brochure_en
Redirect 410 /de/probandenstudie.htm
Redirect 410 /en/firma.htm
Redirect 410 /en/probandenstudie.htm
Redirect 410 /en/company/events
Redirect 410 /en/examplec.htm
Redirect 410 /de/sonden.htm
Redirect 410 /de/examplea.htm
Redirect 410 /en/orthopaedie.htm
Redirect 410 /56
Redirect 410 /hinweis-zur-entsorgung-von-altbatterien
Redirect 410 /de/ansprechspersonen.htm
Redirect 410 /popup/fallbeispielreplantation.htm
Redirect 410 /en/exampletherapie.htm
Redirect 410 /de/fakten.htm
Redirect 410 /en/index.htm
Redirect 410 /de/examplec.htm
Redirect 410 /en/aktuell.htm
Redirect 410 /en/kaninchenstudie.htm
Redirect 410 /de/kaninchenstudie.htm
Redirect 410 /de/aktuell.htm
Redirect 410 /de/orthexample.htm
Redirect 410 /en/orthexample.htm
Redirect 410 /popup/exampleinderzahnmedizin.htm
Redirect 410 /popup/fallbeispielparodontitis.htm
Redirect 410 /de/geschaeftspartner/zahnmedizin
Redirect 410 /50
Redirect 410 /de/firma.htm
Redirect 410 /de/tooths.htm
Redirect 410 /en/sonden.htm
Redirect 410 /en/fakten.htm
Redirect 410 /en/tooths.htm
Redirect 410 /en/examplea.htm
Redirect 410 /en/exampleb.htm
Redirect 410 /de/exampleb.htm
Redirect 410 /de/orthopaedie.htm
Redirect 410 /en/plagiate.htm
Redirect 410 /fra/speziellpatienten.htm
Redirect 410 /page/
Redirect 410 /de/index.htm
Redirect 410 /videos/sitemap.xml
Redirect 410 /anwendungsbereiche/kontraindikation
Redirect 410 /files/patienteninfo.pdf
#>>>>>>>>>>>>>>>>>>>>>>>
#>> DELETE BAD LINKS >>>
#>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>
#>> STATIC COMPRESSION >>>
#>>>>>>>>>>>>>>>>>>>>>>>>>
# Disable dynamic compression
RewriteRule ^(.*)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]
AddEncoding br .cssbr .gifbr .htmlbr .icobr .jpgbr .jsbr .jsonbr .mp4br .pngbr .svgbr .txtbr .webmbr .woffbr .woff2br .xmlbr
AddType application/javascript .jsbr
AddType application/json .jsonbr
AddType font/woff .woffbr
AddType font/woff2 .woff2br
AddType image/gif .gifbr
AddType image/jpeg .jpgbr
AddType image/png .pngbr
AddType image/svg+xml .svgbr
AddType image/x-icon .icobr
AddType text/css .cssbr
AddType text/html .htmlbr
AddType text/plain .txtbr
AddType text/xml .xmlbr
AddType video/mp4 .mp4br
AddType video/webm .webmbr
AddEncoding gzip .cssgz .gifgz .htmlgz .icogz .jpggz .jsgz .jsongz .mp4gz .pnggz .svggz .txtgz .webmgz .woffgz .woff2gz .xmlgz
AddType application/javascript .jsgz
AddType application/json .jsongz
AddType font/woff .woffgz
AddType font/woff2 .woff2gz
AddType image/gif .gifgz
AddType image/jpeg .jpggz
AddType image/png .pnggz
AddType image/svg+xml .svggz
AddType image/x-icon .icogz
AddType text/css .cssgz
AddType text/html .htmlgz
AddType text/plain .txtgz
AddType text/xml .xmlgz
AddType video/mp4 .mp4gz
AddType video/webm .webmgz
RewriteCond %{HTTP:Accept-Encoding} br
RewriteCond %{REQUEST_FILENAME}br -f
RewriteRule ^(.+)\.(css|gif|html|ico|jpg|js|json|mp4|png|svg|txt|webm|woff|woff2|xml)$ $1.$2br [L]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}gz -f
RewriteRule ^(.+)\.(css|gif|html|ico|jpg|js|json|mp4|png|svg|txt|webm|woff|woff2|xml)$ $1.$2gz [L]
#<<<<<<<<<<<<<<<<<<<<<<<<<
#<< STATIC COMPRESSION <<<
#<<<<<<<<<<<<<<<<<<<<<<<<<
I don't know what has been done, but the problem has been solved after I contacted my webhoster.

Htaccess with special character

I would like to do a redirection through the htaccess :
Old URL :
http://www.website.com/?p=5729
New URL :
http://www.website.com/jmsblog/notrevie/18_charlie-raconte-les-chaussettes-qui-puent.html
So I do this in htaccess :
redirect 301 /?p=5729 http://www.website.com/jmsblog/notrevie/18_charlie-raconte-les-chaussettes-qui-puent.html
But it doesn't work, probably because of special character.
Someone as an idea?
***** EDIT ***********
Here is the htaccess file :
# ~~start~~ Do not remove this comment, Prestashop will keep automatically
the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source
solution
# http://www.prestashop.com - http://www.prestashop.com/forums
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
RewriteEngine on
#Domain: www.charlieetjune.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1
[QSA,L]
# Images
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %
{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %
{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %
{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|svg)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
RewriteCond %{THE_REQUEST} /\?p=5729
RewriteRule ^$ http://www.charlieetjune.com/jmsblog/notrevie/18_charlie-raconte-les-chaussettes-qui-puent.html? [L,R]
You can not Redirect Querystring using Redirect directive. You need to use the following Rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} /\?p=5729
RewriteRule ^$ http://example.com/path/? [L,R]
Don't forget to include the ? at the end of the destination url as it removes the old querystring.

Trailing Slash 301 Redirect Issue When ? Is In URL

htaccess | 301 redirect | URI Issue
I recently applied this code to my htaccess to enforce the trailing slash on my URL:
#Trailing backslash
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
The code works great at adding a / at the end of MOST URLs except for those with ? in the middle of the URL. Like below:
https://www.example.com/list-of-all-objects/search?keywords=test
This URL with the currently code that is stated above will change on load to this: https://www.example.com/list-of-all-objects/search/?keywords=test
When it should look like this: https://www.example.com/list-of-all-objects/search?keywords=test/
I have quickly learnt all of the code that I have applied does not work for two reasons.
They don't enforce the / - they just make it possible if its blocked
The term REQUEST_URI or $1 or $2 all don't include ?keyword= (in fact there is nothing that I can find that refers to this part of the URL so I can't include it correctly)
No matter what I do - I can't get a ? or anything after it to be placed before the /. HOW do I get the trailing slash to not be applied before the ? on keyword search but at the end of the URL and continue to be applied at the end of all the other URL's?
Other previously tried methods:
# Force Trailing Slash
enter code hereRewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
Found here: .htaccess Rewrite to Force Trailing Slash at the end
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
Found here: Htaccess: add/remove trailing slash from URL
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>
Found here: http://www.paulund.co.uk/using-htaccess-to-force-trailing-slash
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
Found here: http://ralphvanderpauw.com/seo/how-to-301-redirect-a-trailing-slash-in-htaccess/
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]
Found here: http://enarion.net/web/htaccess/trailing-slash/
# Trailing slash check
# Don't fix direct file links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
Found here: https://moz.com/community/q/trailing-slash-at-end-of-url
# Always append a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [R=301,L]
Found here: https://craftcms.stackexchange.com/questions/9501/force-trailing-slash-on-urls
Below is my complete htaccess file contents:
RewriteEngine On
#Trailing backslash
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
#HTTPS Redirects
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* [QSA,L]
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
Query_string is not part of match in RewriteRule.
To add a trailing slash to query strings, you can use :
RewriteCond %{QUERY_STRING} ([^/]+)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1/ [R,L]
EDIT :
As I already said, query strings can not be handled directly by a RewriteRule directive, so you need a separate rule to add trailing slash to query strings.
The example bellow adds a trailing slash to both parts of the url.
RewriteEngine on
#Add a trailing slash to uri
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ %{REQUEST_URI}/ [NC,L,R]
#Add a trailing slash to query strings
RewriteCond %{QUERY_STRING} ([^/]+)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1/ [R,L]
This will change the following urls :
http://example.com/file
to
http://example.com/file/
Or
http://example.com/file?q=foo
to
http://example.com/file/?q=foo/
(Hope, this helps!)

.htaccess file's puzzling action (code inside)

I have this CMS set up in a folder called localhost:5999/madison/
The .htaccess file (code below) is in the same folder localhost:5999/madison/
If, in a browser, I go to localhost:5999/madison/ or to localhost:5999/madison/index.php or to localhost:5999/madison/xyz where xyz is anything not containing forward slashes, it redirects me to the following file: localhost:5999/madison/inc/views/view-404.php
My question is: Why?
.htaccess code:
RewriteEngine On
ExpiresActive On
#Expire Header
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "now plus 7 days"
</FilesMatch>
ExpiresByType text/css "now plus 7 days"
ExpiresByType text/html "now plus 7 days"
ExpiresDefault "now plus 7 days"
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
RewriteRule ^(assets|inc) - [L]
RewriteRule ^admin[/]?$ admin/index
RewriteRule ^admin/edit/(.*)$ index.php?type=admin&action=edit&page=$1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^admin/(.*)$ index.php?type=admin&action=view&page=$1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^login$ index.php?action=view&type=login&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^forgot-password$ index.php?action=view&type=forgot-password&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^edit/user(/)?$ index.php?action=edit&type=user&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^signup(/)?$ index.php?action=edit&type=user&id=0&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^user/([0-9]+)(/)? index.php?action=view&type=note&user=$1&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^(suggestion|comment)/([0-9]+)(/)? index.php?action=view&type=note&page=open&note_type=$1&note=$2&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^([0-9A-Za-z\-_]+)/(suggestion|comment)/([0-9]+)(/)? index.php?action=view&type=note&page=$1&note_type=$2&note=$3&%1 [L]
#Catch All Pages
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^([0-9A-Za-z\-_]+)(/)? index.php?action=view&type=page&page=$1&%1 [L]
The issue arises because you are hosting the CMS in a sub-folder localhost:5999/madison/ (without changes to the configuration file) and not directly in localhost:5999/
To solve the issue, make the following changes to config.php in /madison/inc/ directory:
config.php
/**
* Server Definitions
*/
define('SERVER_ABS', $_SERVER['DOCUMENT_ROOT']);
define('SERVER_URL', 'http://'.$_SERVER['HTTP_HOST']);
To:
/**
* Server Definitions
*/
define('SERVER_ABS', $_SERVER['DOCUMENT_ROOT'].'/madison');
define('SERVER_URL', 'http://'.$_SERVER['HTTP_HOST'].'/madison');
That seems to be borne out for some custom 404 handler outside your current .htaccess.
Try adding these lines on top of your .htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /madison/
And keep your last rule as:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?action=view&type=page&page=$1 [L,QSA]
Then test this in a new browser to avoid old caches.

isapi rewrite rules remove blog from wordpress url

while i am new to rewrite I will try to outline this problem in english first than start a thread on how to fix this issue with all your help.
I am trying to remove the folder /blog/ from the following url:
http://blog.site.com/blog/2011/05/26/article-name-test/
with:
http://blog.site.com/2011/05/26/article-name-test/
Put this code in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^blog/?(.*)$ /$1 [R=301,L,NE,NC]
Update: Based on your comments
Here is your suggested .htaccess:
RewriteCond %{HTTP_HOST} ^www\.site\.me$ [NC]
RewriteRule ^ http://site.me%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^holisticho\.me$ [NC]
RewriteRule ^blog/ http://blog.site.me [R=301,L,NC]
Chris Hough Current Edits
Options +FollowSymlinks -MultiViews -Indexes
# ------------------------------------------------------------
# Core rewrite rules
# -----------------------------------------------------------
RewriteEngine on
# -----------------------------------------------------------
# Redirect deleting leading www to root domain if no specified sub is used:
# Allowed Subs: our, test, test.blog, local, local.blog
# -----------------------------------------------------------
RewriteCond %{HTTP_HOST} !^(our|test|test\.blog|local|local\.blog)\.holisticho\.me$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.holisticho\.me$
RewriteRule ^(.*)$ http://holisticho.me/$1 [R=301,L]4
# -----------------------------------------------------------
# Temporary Base Redirect Until Phase One Has been completed
# -----------------------------------------------------------
RewriteCond %{HTTP_HOST} ^holisticho\.me$ [NC]
RewriteRule ^(.*)$ http://our.holisticho.me/$1 [R=301,L]
# -----------------------------------------------------------
# Redirect Any Domains not speficied using /blog/ to the primary url for the blog
# -----------------------------------------------------------
RewriteCond %{HTTP_HOST} ^(test|local)\.holisticho\.me$ [NC]
RewriteCond %{REQUEST_URI} ^/blog/$ [NC]
RewriteRule (.*) http://our.holisticho.me/ [R=301,L]
# -----------------------------------------------------------
# User can use /login or /admin to log into WP
# -----------------------------------------------------------
RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
RewriteRule ^(login|admin)$ http://%{HTTP_HOST}/blog/wp-login.php [NC,L]
# -----------------------------------------------------------
# If the wp-admin redirect is triggered redirect to the log in page with no query string
# -----------------------------------------------------------
RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
RewriteCond %{REQUEST_URI} wp-login [NC]
RewriteCond %{QUERY_STRING} redirect_to [NC]
RewriteRule () http://%{HTTP_HOST}/blog/wp-login.php$1? [R=permanent,NC,L]
# -----------------------------------------------------------
# Add hidden "/blog/" to the url structure
# -----------------------------------------------------------
RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
RewriteRule !^blog/ blog%{REQUEST_URI} [L,NE,NC]
# -----------------------------------------------------------
# Wordpress Permalink formatting
# -----------------------------------------------------------
RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
RewriteRule ^index\.php$ - [L,NE,NC]
RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,NE,NC]
# -----------------------------------------------------------
# Site Wide Error Controllers
# -----------------------------------------------------------
ErrorDocument 400 /400.php
ErrorDocument 401 /401.php
ErrorDocument 402 /402.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
# -----------------------------------------------------------
# Using browser cache: FileETag MTime Size
# -----------------------------------------------------------
<ifmodule mod_expires.c>
<filesmatch "\.(jpg|gif|png|css|js)$">
ExpiresActive on
ExpiresDefault "access plus 1 year"
</filesmatch>
</ifmodule>
# -----------------------------------------------------------
# Compress static data
# -----------------------------------------------------------
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
# -----------------------------------------------------------
# Protect blog from hotlinking
# -----------------------------------------------------------
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?holisticho\.me/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /includes/images/administrative/NoHotlinking.png [L]
# -----------------------------------------------------------
# Fix for infinite loops
# -----------------------------------------------------------
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
# -----------------------------------------------------------