Getting this error when performing docker-compose up
Syntax error on line 449 of /etc/httpd/conf/aem.rewrites:
RewriteRule: bad flag delimiters
exited with code 1
Here is the line it's complaining about:
RewriteRule ^/is/image/.*$ http://__PUBLISH__:4503%{REQUEST_URI} [P]
It seems the issue had to do with improper formatting. I used dos2unix for this file and all files related to it.
Related
I'm trying to write a little RewriteRule/RewriteCond but can't find the right resource/tutorial to understand how to achieve my goal. I don't have much knownledge about regex and rewriterules.
That goal is to be able apply a markdown library like Strapdown to a markdown text file when opening it. My idea was :
the user opens the markdown file at http://somedomain.com/myFile.md
RewriteEngine get that you want to do that and redirect you to something like http://somedomain.com/markdown.html?myFile.md
that markdown html page will fetch the content of the markdown file (the filename is in the url parameters) and apply the css library to whatever is loaded and injected in a div.
I think I understood how to redirect the md file to the html document with parameter :
RewriteEngine On
RewriteRule ^(.*).md /markdown.html?md=$1 [QSA,L]
But then the markdown.html page that fetch the .md file is actually fetching the content of markdown.html itself (because of that rule).
So my idea then was to add some character at the end of the filename (like adding a '?' at the end of the file name : "myFile.md?") to be able to catch it in the rewrite rules.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(.*)\?$
RewriteRule ^(.*).md /markdown.html?md=$1 [QSA,L]
But it's not the way to go ... OR my last rewrite synthax is wrong and I don't understand why.
Any ideas ?
Thanks for the help !
I think the issue was that I was trying to use an indetectable pattern (ie : finding '?' at the end of my url).
I changed it to try finding any number as parameter and it works
RewriteEngine On
RewriteCond %{QUERY_STRING} !^([0-9])$
RewriteRule ^(.*).md /markdown.html?md=$1 [QSA,L]
The markdown.html file is now receiving the requested .md file as intended.
By seeing OP's answer I came with some additional improvements in it, please have your htaccess rule file as follows.
RewriteEngine On
RewriteCond %{QUERY_STRING} !^([0-9])$
RewriteRule ^(.*)\.md /markdown.html?md=$1 [QSA,L,NC]
Improvements done in OP's answer:
First escape .md on left side of RewriteRule to make it as a literal character else it may match strings like amd OR bmd etc.
Second use NC flag in your RewriteRule to make it case in-sensitive so that either .md OR .MD both get match.
Also additional suggestion in case your query string could have more than 1 digits in it, change your [0-9] to [0-9]+ in RewriteCond section.
Songs that contain a "#" in the track title give me a 404 error while trying to download from my site. How to fix this?
This is my current .htaccess code:
RewriteRule ^download/([^/]*)-([^/]*).mp3$ download.php?download=$2&pl=$1
The # is never reaching apache. It is a jump-marker and everything in the url after # is not sent to the webserver. The javascript:document.location.hash is jumping to an anchor in the page. You can escape the # with %23 which then should reach your webserver even without htaccess. As you use php, you can use htmlentities($filename) or urlencode($filename) to fix it during output.
From the
Apache manual
By default the special characters such as ?, #will be converted to their hexcode.Using the [NE] flag prevents that from happening.
RewriteRule ^download/([^/]*)-([^/]*)\.mp3$ download.php?download=$2&pl=$1 [NE,QSA,NC,L]
The above example will redirect /download-foo-bar.mp3
to download.php?download=bar&pl=bar#1 . Omitting the [NE] flag will result in the #
being converted to its hexcode %23., which will then result in 404 not found error condition.
And in RewriteRule pattern ,dot (.) is a special characters, it matches any characters. Escape it using a backslash if you want to match a literal dot(.).
I have spent hours trying to get http://www.example.com/awstats to redirect to http://www.example.com/awstats/awstats.pl?config=example.com
The rewrite rule I used is:
RewriteRule ^https?://(www.)?(.*)/awstats/?$ /awstats/awstats.pl?config=$2 [QSA,L]
This doesn't work but it seems that it will work without the colon symbol.
I have tried using the HTML character code and escaping it but nothing I do seems to make any difference.
I have been testing it here: http://htaccess.madewithlove.be/
If I supply this value:
http//www.example.com/awstats
With this rule:
RewriteRule ^https?//(www.)?(.*)/awstats/?$ /awstats/awstats.pl?config=$2 [QSA,L]
Then it works but obviously I need it to process the colon symbol.
Please can someone tell me what I am dong wrong?
Thanks
Robin
In my http logs I see:
"GET /category/f%C2%ADile-to-download/ HTTP/1.1" 301
instead of "GET /category/file-to-download/ HTTP/1.1" 200
I discovered that %C2%AD is a soft hyphen (invisible symbol).
I need to check if a query to Apache contains a soft hypen and if it does to remove it. Any suggestions on the best method to locate soft hyphen and remove it?
I made some tests with RewriteRule, but got stuck.
Thanks!
As I understand it, mod_rewrite uses un-escaped characters, so in order for you to correctly match the soft-hyphen and then remove it, you would need to edit and save your .htaccess file in UTF-8 encoding (most modern editors will do this).
You will then need to enter a soft-hyphen into your rule. The following will (should!?) remove a single soft-hyphen from your input, but as mentioned it relies on the file being in UTF-8 format:
RewriteRule ([^-]*)-([^-]*) $1$2
Note that you would need to replace the - with the actual UTF-8 dash.
Perhaps an easier option would be this:
RewriteRule ([^\xc2\xad]*)\xc2\xad([^\xc2\xad]*) $1$2 [N]
It uses the specific UTF-8 code you're seeing to remove it from the string. The [N] should rerun all the rewrite rules, which will remove any remaining soft-hyphens.
Thanks #icabod
Currently I got this rule working in my case:
RewriteCond %{REQUEST_URI} \xc2\xad [NC]
RewriteRule ([^\xc2\xad]*)[\xc2\xad]+([^\xc2\xad]*) /$1$2 [N,R=301,L,NC]
.htaccess should be in UTF-8 format as mentioned above.
R=301 - redirect with HTTP code 301
NC - case insensitive
But it doesn't work with two soft hyphens in the different places of the URL like this:
/category/f%C2%ADile-to-d%C2%ADownload/
Here is my .htaccess:
...
rewriterule file%20name.htm http://mysite.com/new_name.htm#anchor [r=301,nc,ne]
...
It's not redirected, and I believe this is because it's not targeting the file with the %20 in the name. As for the flags, I used ne to not rewrite the #anchor portion of the redirect.
Also, the flag "nu" breaks my file and I get internal server 500 error.
Thanks you.
When mod_rewrite is invoked, the path has already been decoded as part of Apache's request processing. So, if you want to check for a space, you can do so literally:
RewriteRule file\ name\.html http://example.com/new_name.htm#anchor [R=301,NC,NE,L]
The NU flag doesn't exist, which is why you get an internal server error when you try to use it.
Not the best answer, and can only be used in specific cases, but I changed
file%20name.htm
to
file.*
so it will match any filename that starts with "file", regardless of spaces and special chars.